Submission #623740

#TimeUsernameProblemLanguageResultExecution timeMemory
623740Abrar_Al_SamitGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
0 ms212 KiB
#include<bits/stdc++.h> using namespace std; void PlayGround() { int n; cin>>n; int a[n]; for(int i=0; i<n; ++i) { cin>>a[i]; } if(n==2) { cout<<abs(a[0]-a[1])+1<<'\n'; return; } int b[n-1]; for(int i=1; i<n; ++i) { b[i-1] = a[i]-a[i-1]; } int l = 0, r = n-2; int ans = 0; while(l<r) { while(l<r && b[l]>0) ++l; while(l<r && b[r]<0) --r; if(l==r) { ans += b[l]==0; break; } int cur = min(-b[l], b[r])+1; b[l] += cur; b[r] -= cur; ans += cur; } cout<<ans<<'\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); PlayGround(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...