Submission #936902

#TimeUsernameProblemLanguageResultExecution timeMemory
936902emanIaicepsaGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms512 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__); template<typename T> void _do(T x){cerr<<x<<"\n";} template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);} signed main(){ ios::sync_with_stdio(0), cin.tie(0); int N; cin >> N; vector<ll> arr(N), cost(N), costR(N); for (auto &i: arr) cin >> i; cost[0] = 0; for (int i = 1; i < N; i++) { if (arr[i] > arr[i - 1]) cost[i] = cost[i - 1]; else cost[i] = cost[i - 1] + (arr[i - 1] - arr[i]) + 1; } costR[N - 1] = 0; for (int i = N - 2; i >= 0; i--) { if (arr[i] > arr[i + 1]) costR[i] = costR[i + 1]; else costR[i] = costR[i + 1] + (arr[i + 1] - arr[i]) + 1; } ll answer = 1e18; for (int i = 0; i < N - 1; i++) { answer = min(answer, max(cost[i], costR[i])); } cout << answer << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...