Submission #875207

#TimeUsernameProblemLanguageResultExecution timeMemory
875207makravGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
20 ms7256 KiB
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vei; typedef vector<vei> vevei; #define all(a) (a).begin(), (a).end() #define sz(a) (int) a.size() #define con cout << "NO\n" #define coe cout << "YES\n"; #define str string #define pb push_back #define ff first #define sc second #define ss second #define pii pair<int, int> #define mxe max_element #define mne min_element #define stf shrink_to_fit #define f(i, l, r) for (int i = (l); i < (r); i++) #define double ld #define int ll signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<int> a(n); f(i, 0, n) cin >> a[i]; vector<int> pref(n + 1, 0); for (int i = 2; i <= n; i++) { pref[i] = pref[i - 1] + (a[i - 1] > a[i - 2] ? 0 : a[i - 2] - a[i - 1] + 1); } vector<int> suff(n + 1, 0); for (int i = 2; i <= n; i++) { suff[i] = suff[i - 1] + (a[n - i] > a[n - i + 1] ? 0 : a[n - i + 1] - a[n - i] + 1); } int ans = 1e18; f(i, 0, n) { ans = min(ans, max(pref[i + 1], suff[n - i])); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...