Submission #1183312

#TimeUsernameProblemLanguageResultExecution timeMemory
1183312alterioGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
0 / 100
0 ms400 KiB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    vector<int> ansL(n), ansR(n);
    for (int i = 1; i < n; i++) ansL[i] = ansL[i - 1] + max(0, v[i - 1] - v[i] + 1);
    for (int i = n - 2; i >= 0; i--) ansR[i] = ansR[i + 1] + max(0, v[i + 1] - v[i] + 1);
    int ans = 1e10;
    for (int i = 0; i < n; i++) ans = min(ans, max(ansL[i], ansR[i]));
    cout << ans;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:19:15: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+10' to '2147483647' [-Woverflow]
   19 |     int ans = 1e10;
      |               ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...