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;
ll resp=INFL, prefix[mxn], suff[mxn], v[mxn];
int main(){
fastio;
cin >> n;
for(int i=1; i<=n; i++){
cin >> v[i];
}
for(int i=1; i<=n; i++){
prefix[i]=prefix[i-1]+max(0LL, v[i-1]-v[i]+1);
}
for(int i=n; i>=1; i--){
suff[i]=suff[i+1]+max(0LL, v[i+1]-v[i]+1);
}
for(int i=1; i<=n; i++){
resp=min(resp, max(prefix[i], suff[i]));
}
cout << resp;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |