Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created October 10, 2019 13:39
Show Gist options
  • Save surinoel/baa9d885182ecfd726351f6f3ffccc0b to your computer and use it in GitHub Desktop.
Save surinoel/baa9d885182ecfd726351f6f3ffccc0b to your computer and use it in GitHub Desktop.
#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