Submission #647464

#TimeUsernameProblemLanguageResultExecution timeMemory
647464kkkkkkkkGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> v(n); for (int i=0;i<n;i++) cin >> v[i]; int l=1,r=n-2,brojac=0; while (l<n) if (v[l-1]<v[l]) l++; else break; while (r>=0) if (v[r+1]<v[r]) r--; else break; //cout << l << " " << r << endl; if (l==n||r==-1) { cout << 0 << endl; return 0; } while (l<r) { if (v[l-1]<v[l]) { l++; continue; } if (v[r+1]<v[r]) { r--; continue; } int najm=min(v[l-1]-v[l]+1,v[r+1]-v[r]+1); for (int i=l;i<=r;i++) v[i]+=najm; brojac+=najm; } if (v[l]<=v[l-1]) brojac+=v[l-1]-v[l]+1; cout << brojac; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...