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>
#define pb push_back
#define F first
#define S second
#define int long long
using namespace std;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 2e9 + 1;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int>a(n + 1),pref(n + 1),suf(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
if(i > 1) {
int diff = a[i] - a[i - 1] - 1;
diff *= -1;
pref[i] = pref[i - 1] + max(0ll,diff);
}
}
for(int i = n - 1; i >= 1; i--) {
int diff = a[i] - a[i + 1] - 1;
diff *= -1;
suf[i] = suf[i + 1] + max(0ll,diff);
}
int res = inf;
for(int i = 1; i <= n; i++) res = min(res,max(pref[i],suf[i]));
cout << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |