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;
typedef long long ll;
const int MAXN = 1e6 + 7;
const ll INF = 1e18 + 7;
const int logo = 20;
const int off = 1 << logo;
ll pf[MAXN], arr[MAXN], sf[MAXN];
void solve(){
int n;
cin >> n;
for(int i=1; i<=n; i++) cin >> arr[i];
for(int i=2; i<=n; i++){
pf[i] = pf[i - 1];
if(arr[i] <= arr[i - 1]) pf[i] += 1 + arr[i - 1] - arr[i];
}
for(int i=n-1; i; i--){
sf[i] = sf[i + 1];
if(arr[i] <= arr[i + 1]) sf[i] += 1 + arr[i + 1] - arr[i];
}
ll ans = INF;
for(int i=1; i<=n; i++) ans = min(ans, max(pf[i], sf[i]));
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
//cin >> tt;
while(tt--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |