제출 #954833

#제출 시각아이디문제언어결과실행 시간메모리
954833sandry24Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
20 ms7200 KiB
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; #define pb push_back #define mp make_pair #define f first #define s second void solve(){ int n; cin >> n; vector<ll> a(n), up(n), down(n); for(int i = 0; i < n; i++) cin >> a[i]; up[0] = down[n-1] = 0; for(int i = 1; i < n; i++){ ll curr = max(a[i-1]+1, a[i]); up[i] = up[i-1] + curr - a[i]; } for(int i = n-2; i >= 0; i--){ ll curr = max(a[i+1]+1, a[i]); down[i] = down[i+1] + curr - a[i]; } ll ans = 1e18; for(int i = 0; i < n; i++) ans = min(ans, max(up[i], down[i])); cout << ans << '\n'; } int main(){ // freopen("hex.in", "r", stdin); // freopen("hex.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...