-
Notifications
You must be signed in to change notification settings - Fork 126
/
UVa12100.cc
51 lines (44 loc) · 1.23 KB
/
UVa12100.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Printer Queue, ACM/ICPC NWERC 2006, UVa12100
// ³Â·æ
#include<cassert>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
using namespace std;
int readint() { int x; scanf("%d", &x); return x; }
const int MAXN = 128, MAXP = 10;
int n, m, priority[MAXN], pCnt[MAXP];
int main()
{
int T = readint();
while(T--) {
n = readint(), m = readint();
fill_n(pCnt, MAXP, 0);
fill_n(priority, MAXN, 0);
queue<int> q;
for(int i = 0; i < n; i++) {
q.push(i);
priority[i] = readint();
pCnt[priority[i]]++;
}
int timer = 1;
while(!q.empty()) {
int t = q.front(), p = priority[t];
bool lower = false;
for(int hp = MAXP-1; hp > p; hp--)
if(pCnt[hp] > 0) { lower = true; break; }
q.pop();
if(lower) { q.push(t); continue; }
if(t == m) break;
pCnt[p]--;
assert(pCnt[p] >= 0);
timer++;
}
printf("%d\n", timer);
}
return 0;
}
// 13439845 12100 Printer Queue Accepted C++ 0.019 2014-04-03 14:51:17