Submission #756873

#TimeUsernameProblemLanguageResultExecution timeMemory
756873Niko_shmikoGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; int n, i, j, ans, k; int main(){ cin >> n; int a[n]; for(i=0; i<n; i++){ cin >> a[i]; if(i>0){ a[i-1]=a[i]-a[i-1]; } } i=0; j=n-2; while(i<j){ if(a[i]>0){ i++; continue; } if(a[j]<0){ j--; continue; } k=min(1-a[i], 1+a[j]); a[i]+=k; a[j]-=k; ans+=k; } if(a[i]==0){ ans++; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...