#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
using namespace std;
#define islam_zymchybekov void solve()
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define nl cout<<'\n';
#define int long long
typedef vector<int> vi;
typedef pair<int,int> pi;
int pref[200005];
int suf[200005];
int a[200005];
islam_zymchybekov{
int n,ans=INT_MAX;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
a[0]=-1e5;
a[n+1]=-1e5;
for(int i=1;i<=n;i++){
pref[i]=pref[i-1]+max(a[i-1]-a[i]+1,0ll);
}
for(int i=n;i>0;i--){
suf[i]=suf[i+1]+max(a[i+1]-a[i]+1,0ll);
}
for(int i=1;i<=n;i++){
ans=min(ans,max(pref[i],suf[i]));
}
cout<<ans;
}
main(){
ios;
int T = 1;
// cin >> T;
while(T--){
solve();
}
//cout<<fixed<<setprecision(10);
//cerr<<"Time:"<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";__int128
}
Compilation message
Main.cpp:37:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
37 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |