// #pragma GCC optimize("O3")
// #pragma GCC optimization("Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i, l, r) for (int i = (l); i <= (r); i++)
#define FOD(i, r, l) for (int i = (r); i >= (l); i--)
// #define fi first
// #define se second
// #define pii pair<int, int>
const ll mod = 1e9 + 9;
const int MAXN = 2e5 + 5;
const ll oo = 1e9 + 7;
const int base = 10;
int n, a[MAXN], ps1[MAXN], ps2[MAXN];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("test.txt", "r", stdin);
// freopen("o2.out", "w", stdout);
if(fopen(".inp", "r")){
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
cin >> n;
FOR(i, 1, n){
cin >> a[i];
}
FOR(i, 1, n){
ps1[i]=ps1[i-1];
if(i!=1 && a[i]<a[i-1]+1){
ps1[i]+=(a[i-1]+1-a[i]);
}
}
FOD(i, n, 1){
ps2[i]=ps2[i+1];
if(i!=n && a[i]<a[i+1]+1){
ps2[i]+=(a[i+1]+1-a[i]);
}
}
int ans=oo;
FOR(i, 1, n){
ans=min(ans, max(ps1[i], ps2[i]));
}
cout << ans;
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:32:18: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen(".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:33:18: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen(".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |