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 <iostream>
using namespace std;
long long n, a[200010], ans, ll, rr, l, r, tmp;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
l = 1; r = n; ll = max(0LL,a[l]-a[l+1]+1); rr = max(0LL,a[r]-a[r-1]+1);
while (l < r) {
tmp = min(ll,rr);
ll -= tmp;
rr -= tmp;
ans += tmp;
if (ll == 0) {
l++;
ll = max(0LL,a[l]-a[l+1]+1);
}
if (rr == 0) {
r--;
rr = max(0LL,a[r]-a[r-1]+1);
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |