#include <bits/stdc++.h>
using namespace std;
int main(void) {
cin.tie(nullptr)->sync_with_stdio(false);
int n,r,p;
cin >> n >> r >> p;
vector<int> a(2*n-1);
for (int i = 0; i < 2*n - 1; i++) cin >> a[i];
vector<int> l(n+1);
for (int i = 1; i < n; i++) {
int idx = 2*(i-1);
l[i] = max(a[idx],a[idx + 1]);
}
l[n] = a[2*(n-1)];
vector<bool> st(n+1,false);
for (int i = 2; i <= n; i++) if (l[i] < p) st[i] = true;
vector<int> ps(n+1,0);
for (int i = 1; i <= n; i++) {
ps[i] = ps[i-1];
if (st[i]) ps[i] = i;
}
auto wf = [&](int s) {
int rem = (r-(s-1)) % n;
if (rem == 0) return n;
return n-rem;
};
int bs=1,bf=n+1;
for (int i = 1; i <= n; i++) {
int j;
if (l[i] < p) j = i;
else if (ps[i-1] > 0) j = ps[i-1];
else if (l[1] > p) j=1;
else j = wf(i);
if (j < bf || (j == bf && i > bs)) {
bf = j;
bs = i;
}
}
cout << bs;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |