#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define f1 first
#define s2 second
#define pb push_back
#define mp make_pair
#define ll long long
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);
const int N=5e5+5;
int n,pre[N],dizi[N],ans1,ans,maxl,maxr;
vector<int>v[N];
int main(){
//fri("in.txt");
//fro("out.txt");
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(int i=1;i<=n;i++){
cin>>dizi[i];
v[dizi[i]+i].pb(abs(dizi[i]-i));
if(dizi[i]==i)pre[i]++;
}
for(int i=1;i<=n;i++){
pre[i]+=pre[i-1];
//cout<<pre[i]<<endl;
}
for(int i=0;i<=2*n;i++){
sort(v[i].begin(),v[i].end());
for(int j=0;j<v[i].size();j++){
int l=(i-v[i][j])/2;
int r=(i+v[i][j])/2;
ans1=j+pre[l]+pre[n]-pre[r];
//cout<<l<<" "<<r<<" "<<ans1<<endl;
if(ans1>ans){
maxl=l;
maxr=r;
ans=ans1;
}
}
}
cout<<dizi[maxl]<<" "<<dizi[maxr]<<endl;
return 0;
}
Compilation message
doktor.cpp: In function 'int main()':
doktor.cpp:34:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<v[i].size();j++){
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
12152 KB |
Output is correct |
2 |
Correct |
13 ms |
12152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
12280 KB |
Output is correct |
2 |
Correct |
14 ms |
12152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
12284 KB |
Output is correct |
2 |
Correct |
13 ms |
12152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
12408 KB |
Output is correct |
2 |
Runtime error |
109 ms |
33640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
15384 KB |
Output is correct |
2 |
Correct |
37 ms |
14004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
35 ms |
25336 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
102 ms |
37880 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |