#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int,int>a,pair<int,int>b){
return a.second-a.first+1<b.second-b.first+1;
}
int main()
{
int n;
cin>>n;
int v[n];
int prf[n+5];
prf[0]=0;
for(int i=0;i<n;i++){
cin>>v[i];
prf[i+1]=prf[i]+(i+1==v[i]);
}
vector<int> mp(n*2+5);
vector<pair<int,int> >vps(n);
for(int i=0;i<n;i++){
vps[i]={min(i+1,v[i]),max(i+1,v[i])};
}
sort(vps.begin(),vps.end(),comp);
int l=0,r=0;
int mx=prf[n];
for(int i=0;i<n;i++){
mp[vps[i].first+vps[i].second]++;
if(prf[n]-(prf[vps[i].second]-prf[vps[i].first-1])+mp[vps[i].first+vps[i].second]>mx){
mx=prf[n]-(prf[vps[i].second]-prf[vps[i].first-1])+mp[vps[i].first+vps[i].second];
l=vps[i].first-1; r=vps[i].second-1;
}
}
cout<<v[l]<<' '<<v[r]<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
640 KB |
Output is correct |
2 |
Correct |
168 ms |
9452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
2924 KB |
Output is correct |
2 |
Correct |
51 ms |
3308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
241 ms |
15084 KB |
Output is correct |
2 |
Correct |
274 ms |
15340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
9068 KB |
Output is correct |
2 |
Correct |
185 ms |
14828 KB |
Output is correct |