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 uwu return 0;
using namespace std;
const int SIZE = 2e5 + 5;
int N;
const long long INF = 1e18 + 5;
long long from_f[SIZE], from_e[SIZE], h[SIZE];
int main(){
cin >> N;
for (int i = 1; i <= N;i++){
cin >> h[i];
}
for (int i = 1; i <= N;i++){
from_f[i] = from_f[i - 1] + max(0LL, h[i - 1] - h[i] + 1);
//cout << from_f[i] << '\n';
}
for (int i = N; i >= 1;i--){
from_e[i] = from_e[i + 1] + max(0LL, h[i + 1] - h[i] + 1);
}
long long ans = INF;
for (int i = 1; i <= N;i++){
ans = min(ans, max(from_f[i], from_e[i]));
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |