-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVA-12100.cpp
68 lines (61 loc) · 1.46 KB
/
UVA-12100.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iterator>
#include <queue>
using namespace std;
void findTime(int pos, queue<pair<int, int>> q, priority_queue<pair<int, int>> pq){
int time=1;
while(!pq.empty()){
if(q.front().first>=pq.top().first){
if(q.front().second==pos){
cout << time << endl;
return;
}
time++;
q.pop();
pq.pop();
}
else{
q.push(q.front());
q.pop();
}
}
cout << time << endl;
}
int main(){
int cases, n, pos, val;
cin >> cases;
for(int i=0; i<cases; ++i){
cin >> n >> pos;
queue<pair<int, int>> q;
priority_queue<pair<int, int>> pq;
for(int j=0; j<n; ++j){
cin >> val;
q.push(make_pair(val, j));
pq.emplace(make_pair(val, j));
}
findTime(pos, q, pq);
}
return 0;
}
/*
int main(){
int cases, n, pos, val;
cin >> cases;
for(int i=0; i<cases; ++i){
cin >> n >> pos;
priority_queue<pair<int, int>> pq;
for(int j=0; j<n; ++j){
cin >> val;
pq.emplace(make_pair(val, j));
}
int time;
for(time=1; !pq.empty() && pq.front().second!=pos; ++time){
pq.pop();
}
cout << time << endl;
}
return 0;
}
*/