Submission #658854

#TimeUsernameProblemLanguageResultExecution timeMemory
658854GrandTiger1729Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms340 KiB
#include <iostream> #include <vector> using namespace std; const long long INF = 1e18; int main(){ cin.tie(0)->sync_with_stdio(0); int n; cin >> n; vector<int> a(n + 2); for (int i = 1; i <= n; i++){ cin >> a[i]; } vector<int> b = a; long long pref[n + 2]{}; for (int i = 1; i <= n; i++){ pref[i] = pref[i - 1] + max(b[i], b[i - 1] + 1) - b[i]; b[i] = max(b[i], b[i - 1] + 1); } vector<int> c = a; long long suff[n + 2]{}; for (int i = n; i >= 1; i--){ suff[i] = suff[i + 1] + max(c[i], c[i + 1] + 1) - c[i]; c[i] = max(c[i], c[i + 1] + 1); } long long ans = INF; for (int i = 0; i <= n; i++){ long long res = max(pref[i], suff[i + 1]) + (pref[i] == suff[i + 1] && b[i] == c[i + 1]); ans = min(ans, res); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...