This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define F first
#define S second
#define PB push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define vi vector<int>
#define vl vector<ll>
#define CASE int t;cin>>t;for(int ca=1;ca<=t;ca++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;
const int MAX = 1 << 20, MOD = 1e9 + 7;
ll a[MAX];
void solve(){
int n;
cin >> n;
int mx = 0, id;
for(int i = 1;i <= n;i++){
cin >> a[i];
if(a[i] > mx){
mx = a[i];
id = i;
}
}
ll ans1 = 0, ans2 = 0;
for(int i = 1;i < id;i++){
ans1 += max(0LL, a[i - 1] + 1 - a[i]);
}
for(int i = id + 1;i <= n;i++){
ans2 += max(0LL, a[i + 1] + 1 - a[i]);
}
cout << max(ans1, ans2) << '\n';
}
int main(){
IOS
// CASE
solve();
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:25:17: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
25 | int mx = 0, id;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |