This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int n, r, s, a[N], b[N];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> r >> s;
// r=(r-n*2)%(n*2)+n*2;
for (int i=1; i<n*2; ++i) cin >> b[i];
pair<int, int> ans={n*2, n};
for (int i=1; i<=n; ++i){
for (int j=1; j<i*2; ++j) a[j]=b[j];
a[i*2]=s;
for (int j=i*2+1; j<=n*2; ++j) a[j]=b[j-1];
for (int _=1; _<=r; ++_){
for (int j=1; j<=n*2; j+=2) if (a[j]>a[j+1]) swap(a[j], a[j+1]);
swap(a[1], a[2]);
int tmp=a[1];
for (int j=3; j<=n*2; j+=2) a[j-2]=a[j];
a[n*2-1]=tmp;
}
int pos=0;
for (int j=1; j<=n*2; ++j) if (a[j]==s) pos=(j+1)/2;
ans=min(ans, {pos, -i});
}
cout << -ans.second << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |