Submission #1154724

#TimeUsernameProblemLanguageResultExecution timeMemory
1154724minggaGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
27 ms4936 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define ln '\n' #define int long long const int N = 2e5 + 7; const int inf = 2e18; int n, a[N], rig[N], d[N]; signed main() { cin.tie(0) -> sync_with_stdio(0); cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i]; } int ans = inf; for(int i = 1; i <= n; i++) { d[i] = a[i] - a[i - 1]; // cerr << d[i] << ' '; } // cerr << ln; for(int i = n; i > 0; i--) { rig[i] = rig[i + 1]; if(d[i] >= 0) rig[i] += d[i] + 1; } int cur = 0; for(int i = 1; i <= n; i++) { if(d[i] <= 0) cur += 1 - d[i]; ans = min(ans, max(cur, rig[i + 1])); } cout << ans << ln; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...