제출 #1016238

#제출 시각아이디문제언어결과실행 시간메모리
1016238ZeroCoolGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array #define int long long const int N = 5e5 + 20; const int INF = 1e17; const int MOD = 8; const int X = 4000; const int LOG = 21; //#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") //#pragma GCC optimize("O3") signed main(){ios_base::sync_with_stdio(false);cin.tie(0); int n; cin>>n; int A[n]; for(int i = 0;i < n;i++)cin>>A[i]; int up[n], dwn[n]; up[0] = dwn[n-1] = 0; for(int i = 1;i < n;i++)up[i] = up[i-1] + max(0ll, A[i-1] - A[i] + 1); for(int i = n- 2;i >= 0;i--)dwn[i] = dwn[i + 1] + max(0ll, A[i+1] - A[i] + 1); int ans = INF; for(int i = 0;i < n;i++)ans = min(ans, up[i] + dwn[i]); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...