제출 #891595

#제출 시각아이디문제언어결과실행 시간메모리
891595hafoGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms4580 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned ll #define pb push_back #define pa pair<int, int> #define pall pair<ll, int> #define fi first #define se second #define TASK "test" #define Size(x) (int) x.size() #define all(x) x.begin(), x.end() using namespace std; template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;} template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;} const int MOD = 1e9 + 7; const int LOG = 20; const int maxn = 2e5 + 7; const ll oo = 1e18 + 69; int n, a[maxn], pre_d[maxn], suf_d[maxn], val_pre[maxn], val_suf[maxn]; ll pre[maxn], suf[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen(TASK".inp", "r", stdin); //freopen(TASK".out", "w", stdout); cin>>n; for(int i = 1; i <= n; i++) cin>>a[i]; val_pre[1] = a[1]; for(int i = 2; i <= n; i++) { val_pre[i] = max(val_pre[i - 1] + 1, a[i]); pre_d[i] = val_pre[i] - a[i]; pre[i] = pre[i - 1] + max(0, pre_d[i] - pre_d[i - 1]); } val_suf[n] = a[n]; for(int i = n - 1; i >= 1; i--) { val_suf[i] = max(val_suf[i + 1] + 1, a[i]); suf_d[i] = val_suf[i] - a[i]; suf[i] = suf[i + 1] + max(0, suf_d[i + 1] - suf_d[i]); } ll ans = oo; for(int i = 1; i <= n; i++) { int val = max(val_pre[i], val_suf[i]); int tmp = val - a[i]; ll l = pre[i - 1] + max(0, tmp - pre_d[i - 1]); ll r = suf[i + 1] + max(0, suf_d[i + 1] - tmp); mini(ans, max(l, r)); } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...