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;
typedef long long ll;
#define int ll
#define starburst ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define N 100005
void solve(){
int n, ans = 1e18; cin >> n;
vector<int> v(n), cnt1(n, 0), cnt2(n, 0);
for(auto &x:v) cin >> x;
for(int i = 1; i < n; ++i){
int j = n - i - 1;
cnt1[i] = max(0ll, v[i - 1] - v[i] + 1) + cnt1[i - 1];
cnt2[j] = max(0ll, v[j + 1] - v[j] + 1) + cnt2[j + 1];
}
for(int i = 0; i < n; ++i){
ans = min(ans, max(cnt1[i], cnt2[i]));
}
cout << ans << '\n';
}
signed main(){
starburst
int t = 1; //cin >> t;
while(t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |