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 maxn = 1000000;
int v[maxn];
int d[maxn];
int f[maxn*2];
int l[maxn*2];
int cnt[maxn*2];
int pref[maxn*2];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
pref[i] = pref[i-1];
if (a == i) pref[i]++;
v[i] = a;
d[i] = i-n+a-1;
if (f[d[i]+n] == 0) f[d[i]+n] = i;
l[d[i]+n] = i;
cnt[d[i]+n]++;
}
for (int i = 0; i <= 2*n; i++) {
if (f[i] == 0) continue;
int ini = min(1+n-(l[i]-d[l[i]]), f[i]);
int fim = max(1+n-(f[i]-d[l[i]]), l[i]);
if (ini == fim) continue;
cnt[i] -= pref[fim]-pref[ini-1];
}
int dbest = -1;
int di;
for (int i = 0; i <= 2*n; i++) {
if (cnt[i] > dbest) {
dbest = cnt[i];
di = i;
}
}
int ini = min(1+n-(l[di]-d[l[di]]), f[di]);
int fim = max(1+n-(f[di]-d[l[di]]), l[di]);
cout << v[ini] << " " << v[fim] << "\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... |