Submission #756776

#TimeUsernameProblemLanguageResultExecution timeMemory
756776otariusGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
2 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long void solve() { int n; cin >> n; int arr[n + 1], ans = 1e18; for (int i = 1; i <= n; i++) cin >> arr[i]; int pref[n + 1], suff[n + 1]; pref[1] = 0; suff[n] = 0; for (int i = 2; i <= n; i++) { if (arr[i - 1] < arr[i]) pref[i] = pref[i - 1]; else pref[i] = pref[i - 1] + arr[i - 1] - arr[i] + 1; } for (int i = n - 1; i >= 1; i--) { if (arr[i] > arr[i + 1]) suff[i] = suff[i + 1]; else suff[i] = suff[i + 1] + arr[i + 1] - arr[i] + 1; } for (int i = 1; i <= n; i++) { ans = min(ans, max(pref[i], suff[i])); } cout << ans; } int main() { int t = 1; // cin >> t; while (t--) { solve(); cout << '\n'; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:8:27: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
    8 |     int arr[n + 1], ans = 1e18;
      |                           ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...