Submission #1010427

#TimeUsernameProblemLanguageResultExecution timeMemory
1010427vjudge1Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms348 KiB
#include "bits/stdc++.h" typedef long long ll; using namespace std; #define int long long signed main(){ int n; cin >> n; int a[n]; int maxx = 0, ii = 0; for(int i = 0; i < n; i++){ cin >> a[i]; if(a[i] > maxx){ maxx = a[i]; ii = i; } } int ans = 0; int l = ii, r = ii; while(true){ if(l > 0 && a[l-1] < a[l]) l--; if(r < n-1 && a[r+1] < a[r]) r++; if(r < n-1 && l > 0 && a[l-1] >= a[l] && a[r+1] >= a[r]){ ans+= max(a[l-1]-a[l]+1, a[r+1]-a[r]+1); a[l] += a[l-1]-a[l]+1; a[r] += a[r+1]-a[r]+1; l--; r++; } if(r < n-1 && a[r+1] >= a[r]){ ans += a[r+1]-a[r]+1; a[r] += a[r+1]-a[r]+1; r++; } if(l > 0 && a[l-1] >= a[l]){ ans += a[l-1]-a[l]+1; a[l] += a[l-1]-a[l]+1; l--; } if(l == 0 && r == n-1) break; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...