제출 #1010444

#제출 시각아이디문제언어결과실행 시간메모리
1010444vjudge1Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
0 ms600 KiB
#include "bits/stdc++.h" typedef long long ll; using namespace std; //#define int long long signed main(){ ll n; cin >> n; ll a[n]; ll maxx = 0, ii = 0; for(int i = 0; i < n; i++){ cin >> a[i]; if(a[i] > maxx){ maxx = a[i]; ii = i; } } ll ans = 0; ll 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...