Submission #758960

#TimeUsernameProblemLanguageResultExecution timeMemory
758960ridicheGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms328 KiB
#include <iostream> #define INT_MAX 2147483647 using namespace std; int a[200005]; int cr[200005], cn[200005]; int dr[200005], dn[200005]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } cn[0] = a[0]; for (int i = 1; i < n; i++) { cn[i] = a[i] + cr[i - 1]; cr[i] = cr[i - 1]; if (cn[i] <= cn[i - 1]) { cr[i] += (cn[i - 1] - cn[i]) + 1; cn[i] = cn[i - 1] + 1; } } dn[n - 1] = a[n - 1]; for (int i = n - 2; i >= 0; i--) { dn[i] = a[i] + dr[i + 1]; dr[i] = dr[i + 1]; if (dn[i] <= dn[i + 1]) { dr[i] += (dn[i + 1] - dn[i]) + 1; dn[i] = dn[i + 1] + 1; } } int r = INT_MAX; for (int i = 0; i < n; i++) { r = min(r, max(cr[i], dr[i])); } cout << r; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...