Submission #696302

#TimeUsernameProblemLanguageResultExecution timeMemory
696302yaufungGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0); int n; cin >> n; long long ans = 0; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } int l = 2, r = n - 1; while (l <= n && a[l] > a[l - 1]) l++; while (r >= 1 && a[r] > a[r + 1]) r--; if (l > n || r < 1) { cout << "0\n"; return 0; } while (l <= r) { int add = min(abs(a[l] - a[l - 1]), abs(a[r] - a[r + 1])) + 1; a[l] += add; a[r] += add; ans += add; while (l <= n && a[l] > a[l - 1]) l++; while (r >= 1 && a[r] > a[r + 1]) r--; } if (l <= n && r >= 1 && a[l] == a[r]) ans++; cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...