Submission #1010471

#TimeUsernameProblemLanguageResultExecution timeMemory
1010471m5588ohammedGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
63 ms11724 KiB
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n; cin>>n; int arr[n],a[n]; for(int i=0;i<n;i++){ cin>>arr[i]; a[i]=arr[i]; } int pre[n+1]={},suf[n+1]={},ansP[n+1]={},ansS[n+1]={}; for(int i=1;i<n;i++){ if(pre[i]<=arr[i-1]-arr[i]){ pre[i]=((arr[i-1]-arr[i]))+1; arr[i]=arr[i-1]+1; } } for(int i=n-2;i>=0;i--){ if(suf[i]<=a[i+1]-a[i]){ suf[i]=(a[i+1]-a[i])+1; a[i]=a[i+1]+1; } } int cnt=0; for(int i=1;i<n;i++){ if(pre[i]-pre[i-1]>0) cnt+=pre[i]-pre[i-1]; ansP[i]=cnt; } cnt=0; for(int i=n-2;i>=0;i--){ if(suf[i]-suf[i+1]>0) cnt+=suf[i]-suf[i+1]; ansS[i]=cnt; } int mn=1e18; for(int i=0;i<n;i++){ if(i==0) mn=min(mn,ansS[i]); else if(i==n-1) mn=min(mn,ansP[i]); else { int ANS=max(ansP[i],ansS[i+1]); if(a[i+1]==arr[i]) ANS++; mn=min(ANS,mn); } } cout<<mn<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...