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;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n,sb = 0,br = 0,ans = LLONG_MAX;
cin >> n;
vector<long long> haha(n);
vector<long long> wow(n-1);
vector<long long> wut(n-1);
for(long long i = 0; i < n; i++) {
cin >> haha[i];
}
for(long long i = 0; i < n-1; i++) {
wow[i] = max(haha[i]-haha[i+1]+1,0LL);
sb+=wow[i];
wut[i] = max(haha[n-i-1]-haha[n-i-2]+1,0LL);
}
ans = min(ans,sb);
for(long long i = n-2; i >= 0; i--) {
sb-=wow[i];
br+=wut[n-i-2];
ans = min(ans,max(sb,br));
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |