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;
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |