-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP12100.cpp
45 lines (42 loc) · 878 Bytes
/
P12100.cpp
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
#include <iostream>
#include <deque>
#include <algorithm>
typedef std::pair<int,int> job; // id, priority
#define PRIO second
#define ID first
int main() {
int N, n, m;
std::cin >> N;
for(int ig = 0; ig < N; ++ig) {
// Read and set up:
std::cin >> n >> m;
//std::cerr << "n=" << n << ", m=" << m << std::endl;
int *priorities = new int[n];
std::deque<job> deck;
for(int i = 0; i < n; ++i) {
job j;
std::cin >> j.PRIO;
j.ID = i;
priorities[i] = j.PRIO;
deck.push_back(j);
}
std::sort(priorities, &priorities[n]);
int time = 1;
while(true) {
job j = deck.front();
deck.pop_front();
if(j.PRIO == priorities[n-1]) {
if(j.ID == m) {
std::cout << time << std::endl;
break;
}
--n; // print :)
++time;
}
else {
deck.push_back(j);
}
}
}
return 0;
}