제출 #370943

#제출 시각아이디문제언어결과실행 시간메모리
370943kshitij_sodaniGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
41 ms5120 KiB
//#pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long llo; #define mp make_pair #define pb push_back #define a first #define b second #define endl '\n' llo n; llo it[200001]; llo pre[200001]; llo pre2[200001]; llo cur[200001]; llo cur2[200001]; /*llo ans=0; void solve(llo l,llo r){ if(l==r){ return ; } if(it[l]<=it[r]){ llo mi=it[l+1]; for(llo i=l+1;i<=r;i++){ mi=min(mi,it[i]); } if(mi<=it[l]){ for(llo i=l+1;i<=r;i++){ it[i]+=it[l]-mi+1; } ans+=it[l]-mi+1; } solve(l+1,r); } else{ llo mi=it[l]; for(llo i=l;i<r;i++){ mi=min(mi,it[i]); } if(mi<=it[r]){ for(llo i=l;i<r;i++){ it[i]+=it[r]-mi+1; } ans+=it[r]-mi+1; } solve(l,r-1); } }*/ int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; for(llo i=0;i<n;i++){ cin>>it[i]; } //solve(0,n-1); //llo ma=it[0]; //cur[0]=it[0]; for(int i=1;i<n;i++){ pre[i]=pre[i-1]; if(it[i]<=it[i-1]){ pre[i]+=(it[i-1]-it[i]+1); //cur[i]=cur[i-1]+it[i]; } else{ //cur[i]=it[i]; } } cur2[n-1]=it[0]; for(int i=n-2;i>=0;i--){ pre2[i]=pre2[i+1]; if(it[i]<=it[i+1]){ pre2[i]+=(it[i+1]-it[i]+1); // cur2[i]=cur2[i+1]+1; } else{ //cur2[i]=it[i]; } } llo ans=1e18; for(int i=0;i<n;i++){ // cout<<pre[i]<<":"<<pre2[i]<<endl; ans=min(ans,max(pre[i],pre2[i])); } cout<<ans<<endl; /* llo ma=0; for(llo i=1;i<n;i++){ ma=max(ma,it[i-1]); pre[i]=pre[i-1]; if(it[i]<=ma){ pre[i]+=ma-it[i]+1; } } ma=0; for(llo i=n-2;i>=0;i--){ ma=max(ma,it[i+1]); pre2[i]=pre2[i+1]; if(it[i]<=ma){ pre2[i]+=ma-it[i]+1; } } llo ans=pre[0]+pre2[0]; for(llo i=0;i<n;i++){ ans=min(ans,pre[i]+pre2[i]); }*/ //cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...