Submission #706131

#TimeUsernameProblemLanguageResultExecution timeMemory
706131PringGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
24 ms3440 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> pii; const int MXN = 200005; int n, a[MXN], d[MXN]; int getANS() { int l = 0, r = n - 2, ans = 0; while (l < n - 1 && d[l] > 0) l++; while (r >= 0 && d[r] < 0) r--; if (l == n - 1 || r == -1) return 0; while (l < r) { int small = min(1 - d[l], d[r] + 1); d[l] += small; d[r] -= small; ans += small; while (l < n - 1 && d[l] > 0) l++; while (r >= 0 && d[r] < 0) r--; } if (l == r && d[l] == 0) ans++; return ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) d[i - 1] = a[i] - a[i - 1]; cout << getANS() << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...