Submission #647481

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