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 endl "\n"
#define ll long long
#define pb push_back
#define mp make_pair
const long long MOD = 1e9+7;
const long long INF = 1e18;
void solve(vector<ll> arr, int n, vector<ll> &pre)
{
for(int i = 1; i<n; i++)
{
pre[i] = max(0LL, arr[i-1]-arr[i]+1) + pre[i-1];
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<ll> arr(n);
for(int i = 0; i<n; i++)
cin >> arr[i];
vector<ll> pre1(n, 0), pre2(n, 0);
solve(arr, n, pre1);
reverse(arr.begin(), arr.end());
solve(arr, n, pre2);
ll res = 1e18;
for(int i = 0; i<n; i++)
{
res = min(res, max(pre1[i], pre2[n-i-1]));
}
cout << res << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |