forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF.cpp
More file actions
36 lines (34 loc) · 675 Bytes
/
F.cpp
File metadata and controls
36 lines (34 loc) · 675 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
int n, id, x, test;
cin >> test;
while (test--)
{
cin >> n >> id;
vector < pair<int,int> > q;
for (int i = 0; i < n; i++)
{
cin >> x;
q.push_back(make_pair(x, i == id));
}
int t = 0;
while (!q.empty())
{
if (max_element(q.begin(), q.end()) -> first > q[0].first)
rotate(q.begin(), q.begin() + 1, q.end());
else
{
t++;
if (q[0].second)
{
cout << t << endl;
break;
}
q.erase(q.begin());
}
}
}
}