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;
int main()
{
int n;
cin >> n;
int a[n], idx[1 + n];
for(int i = 0; i < n; i ++) {
cin >> a[i];
idx[a[i]] = i + 1;
}
int cnt[3 * n] = {};
for(int i = 1; i <= n; i ++)
cnt[idx[i] + i]++;
int pref[n + 1] = {};
for(int i = 0; i < n; i ++) {
pref[i + 1] = pref[i];
if(i + 1 == a[i])
pref[i + 1]++;
}
pair<int,int> ans = {1, 1};
int mx = 0;
for(int i = 1; i <= n; i ++)
{
int j = max(idx[i], i), k = min(idx[i], i);
int profit = cnt[i + idx[i]] - (pref[j] - pref[k - 1]);
if(abs(idx[i] - i) % 2 == 0)
{
int mid = (i + idx[i]) / 2;
if(a[mid - 1] == mid) profit++;
}
// cerr << "profit : " << profit << endl;
if(profit > mx)
{
mx = profit;
ans = {a[k - 1], a[j - 1]};
}
cnt[idx[i] + i] = 0;
}
cout << ans.first << ' ' << ans.second << endl;
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... |