# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
393407 | ahmet | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++14 | 33 ms | 6892 KiB |
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 zaman cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "
#define rep(i,n) for(long long (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (long long (i)=(a); (i)<=(b); ++(i))
#define endl '\n'
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define mp make_pair
const int mx=2e5+6;
ll l[mx],r[mx];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
ll n;cin >> n;
ll ans=1e18+2;
vector <ll> a(n+1);
ref(i,1,n)cin >> a[i];
ref(i,2,n){
l[i]=l[i-1]+max(0LL,a[i-1]-a[i]+1);
}
for(int i=n-1;i>=1;--i){
r[i]=r[i+1]+max(0LL,a[i+1]-a[i]+1);
}
for(int i=1;i<=n;++i){
ans=min(ans,max(l[i],r[i]));
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |