Created
October 10, 2019 13:39
-
-
Save surinoel/baa9d885182ecfd726351f6f3ffccc0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <deque> | |
using namespace std; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int tc; | |
cin >> tc; | |
while (tc--) { | |
int n, m; | |
cin >> n >> m; | |
vector<int> p(n); | |
for (int i = 0; i < n; i++) { | |
cin >> p[i]; | |
} | |
deque<int> q; | |
for (int i = 0; i < n; i++) { | |
q.push_back(i); | |
} | |
vector<int> ans; | |
while(!q.empty()) { | |
int x; | |
x = q.front(); | |
q.pop_front(); | |
bool ok = true; | |
for (int i = 0; i < q.size(); i++) { | |
if (p[x] < p[q[i]]) { | |
ok = false; | |
break; | |
} | |
} | |
if (!ok) { | |
q.push_back(x); | |
} | |
else { | |
ans.push_back(x); | |
} | |
} | |
for (int i = 0; i < n; i++) { | |
if (ans[i] == m) { | |
cout << i + 1 << '\n'; | |
break; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment