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 inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int N = 500000 + 3;
int n, a[N], b[N], sum[N];
map <int, int> cnt, last;
pii mx = {-inf, -inf};
int get_sum(int l, int r){
if (!l) return sum[r];
return sum[r] - sum[l - 1];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++){
b[i] = a[i] + i;
cnt[b[i]]++;
last[b[i]] = i;
if (a[i] == i + 1) sum[i] = 1;
if (i) sum[i] += sum[i - 1];
}
for (auto u: cnt){
mx = max(mx,make_pair(u.second - get_sum(a[last[u.first]] - 1, last[u.first]), u.first));
}
// cout << mx.first << " " << last[mx.second] << "\n";
// for (auto u: cnt) cout << u.first << " : " << u.second << "\n";
// cout << mx.first << " " << mx.second << "!!!\n";
// int l = n, r = -1;
// for (int i = 0; i < n; i++){
// if (b[i] == mx.second){
// l = a[i] - 1;
// r = i;
// }
// }
// cout << a[l]<< " " << a[r];
cout << a[a[last[mx.second]] - 1] << " " << a[last[mx.second]] << "\n";
}
# | 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... |