Submission #957481

#TimeUsernameProblemLanguageResultExecution timeMemory
957481AcanikolicGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
19 ms7416 KiB
#include <bits/stdc++.h> #define pb push_back #define F first #define S second #define int long long using namespace std; const int N = 1e5 + 10; const int mod = 1e9 + 7; const int inf = 1e18 + 1; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int>a(n + 1),pref(n + 1),suf(n + 1); int mx = 0; for(int i = 1; i <= n; i++) { cin >> a[i]; if(i > 1) { int diff = a[i - 1] - a[i] + 1; pref[i] = pref[i - 1] + max(0ll,diff); } } for(int i = n - 1; i >= 1; i--) { int diff = a[i + 1] - a[i] + 1; suf[i] = suf[i + 1] + max(0ll,diff); } int res = inf; for(int i = 1; i <= n; i++) res = min(res,max(pref[i],suf[i])); cout << res; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:27:6: warning: unused variable 'mx' [-Wunused-variable]
   27 |  int mx = 0;
      |      ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...