# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
691339 | guagua0407 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 43 ms | 6952 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.
/*
燒雞
燒雞
燒雞 好想進選訓
燒雞
燒雞
*/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
int main() {_
//setIO("wayne");
int n;
cin>>n;
int num[n+1];
for(int i=1;i<=n;i++){
cin>>num[i];
}
int dif[n+1];
for(int i=2;i<=n;i++){
dif[i]=num[i]-num[i-1];
}
ll pre[n+1],suf[n+1];
pre[1]=0;
for(int i=2;i<=n;i++){
pre[i]=pre[i-1];
if(dif[i]<=0){
pre[i]+=-1*dif[i]+1;
}
}
suf[n]=0;
for(int i=n-1;i>=1;i--){
suf[i]=suf[i+1];
if(dif[i+1]>=0){
suf[i]+=dif[i+1]+1;
}
}
ll ans=1e18;
for(int i=1;i<=n;i++){
ans=min(ans,max(pre[i],suf[i]));
}
cout<<ans;
return 0;
}
//maybe its multiset not set
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |