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 MOD 1000000007
#define mxn 200005
#define mxm 105
#define f first
#define s second
#define pb push_back
#define es " "
#define endl '\n'
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
typedef pair<string, string> pii;
typedef pair<int, pii> pip;
int n, v[mxn], ma, pos, pos2, pos3;
ll need[mxn], resp, atual;
int main(){
fastio;
cin >> n;
for(int i=1; i<=n; i++){
cin >> v[i];
if(v[i]>=ma){
ma=v[i];
pos=i;
}
}
for(int i=n; i>=pos; i--){
if(v[i]<=v[i+1]+need[i+1]){
need[i]=(v[i+1]+need[i+1])-v[i]+1;
}
}
for(int i=1; i<=pos; i++){
if(v[i]<=v[i-1]+need[i-1]){
need[i]=(v[i-1]+need[i-1])-v[i]+1;
}
}
pos2=1, pos3=n;
for(int i=pos-1; i>=1; i--){
if(need[i]){
pos2=i;
break;
}
}
for(int i=pos+1; i<=n; i++){
if(need[i]){
pos3=i;
break;
}
}
for(int i=1; i<pos2; i++){
atual=max(atual, need[i]);
}
resp+=atual;
atual=0;
for(int i=pos2; i<=pos3; i++){
atual=max(atual, need[i]);
}
resp+=atual;
atual=0;
for(int i=pos3+1; i<=n; i++){
atual=max(atual, need[i]);
}
resp+=atual;
cout << resp;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |