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;
#define sp << " " <<
#define int long long
#define vi vector<int>
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
#define pb push_back
const int N = 5e5+1;
const int inf = 1e9+1;
vi bit(N,0);
int n;
void add(int p,int v) {
for (int i=p;i<=n;i+=i&-i) bit[i]+=v;
}
int get(int p) {
int ans = 0;
for (int i=p;i>0;i-=i&-i) ans+=bit[i];
return ans;
}
void solve() {
cin >> n;
vi a(n+1);
F(i,n) cin >> a[i];
vi v(n+1);
F(i,n) v[i] = a[i]+i;
pii anss;
int best = 0;
vi poss[2*n+1];
F(i,n) poss[v[i]].push_back(i);
for (int i=1;i<=n;i++){
for (auto it : poss[i+1]) add(it,1);
if (get(i) > best) {
best = get(i);
anss = {1,i};
}
for (auto it : poss[i+1]) add(it,-1);
}
for (int i=1;i<=n;i++) {
//[i,n]
for (auto it : poss[n+i]) add(it,1);
if (get(n)-get(i-1) > best) {
best = get(n)-get(i-1);
anss = {i,n};
}
for (auto it : poss[n+i]) add(it,-1);
}
cout << a[anss.first] sp a[anss.second] << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int t = 1;
//cin >> t;
F(i,t) solve();
}
# | 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... |