Submission #682057

#TimeUsernameProblemLanguageResultExecution timeMemory
682057viciousGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
26 ms6164 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fi first #define si second typedef pair<int,int> pi; typedef tuple<int,int,int> ti; template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;} template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;} void debug_out() {cerr<<endl;} template <typename Head, typename... Tail> void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);} #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__) const int N = 200010; const ll INF=1e18; int n,arr[N]; ll dpf[N], dpb[N], ans=INF; int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin.exceptions(ios::badbit|ios::failbit); cin >> n; for (int i = 1; i <= n; ++i) { cin >> arr[i]; if (i==1) dpf[i]=0; else { if (arr[i]>arr[i-1]) dpf[i]=dpf[i-1]; else dpf[i] = dpf[i-1]+(arr[i-1]-arr[i])+1; } } for (int i = n; i >= 1; --i) { if (i==n) dpb[i]=0; else { if (arr[i]>arr[i+1]) dpb[i]=dpb[i+1]; else dpb[i] = dpb[i+1]+(arr[i+1]-arr[i])+1; } } for (int i = 1; i <= n; ++i) { chmin(ans, max(dpf[i],dpb[i])); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...