Submission #1010431

#TimeUsernameProblemLanguageResultExecution timeMemory
1010431vjudge1Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
0 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; if((ii > 0 && a[ii] == a[ii-1]) || (ii < n-1 && a[ii] == a[ii+1])){ a[ii]++; ans++; } 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++; } else 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++; } else 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...