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>
#define sz(x) int(x.size())
#define N 5 * 100500
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define el '\n'
using namespace std;
int n, pf[N], a[N], ans, al = 0, ar = 0;
vector <pair <int, int> > v[2 * N];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
pf[i] = (i - 1 < 0) ? 0 : pf[i - 1];
pf[i] += (a[i] == i);
}
for (int i = 0; i < n; i++) {
int l = i, r = a[i];
if (l > r)
swap(l, r);
v[l + r].pb(mp(l, r));
}
for (int i = 0; i < 2 * n; i++) {
sort(v[i].rbegin(), v[i].rend());
for (int j = 0; j < sz(v[i]); j++) {
int l = v[i][j].ft, r = v[i][j].sd;
int cur = (j + 1) + (pf[n - 1] - pf[r]) + (l - 1 < 0 ? 0 : pf[l - 1]);
if (cur > ans) {
al = l;
ar = r;
ans = cur;
}
}
}
cerr << ans << el;
cout << a[al] + 1 << ' ' << a[ar] + 1;
}
# | 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... |