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 eb emplace_back
#define all(x) x.begin(), x.end()
#define int long long
constexpr int sz = 2e5 + 5;
int n, a[sz], pref[sz], suff[sz];
int ans = (int)1E18 + 7;
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n;
for(register int i = 1; i <= n; ++i){
cin >> a[i];
}
for(register int i = 1; i <= n; ++i){
pref[i] = pref[i-1] + max(0ll, a[i-1] - a[i] + 1);
}
for(register int i = n; i >= 1; --i){
suff[i] = suff[i+1] + max(0ll, a[i+1] - a[i] + 1);
}
for(register int i = 1; i <= n; ++i){
ans = min(ans, max(pref[i], suff[i]));
}
cout << ans << '\n';
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:17:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
17 | for(register int i = 1; i <= n; ++i){
| ^
Main.cpp:21:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
21 | for(register int i = 1; i <= n; ++i){
| ^
Main.cpp:25:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
25 | for(register int i = n; i >= 1; --i){
| ^
Main.cpp:29:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
29 | for(register int i = 1; i <= n; ++i){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |