Submission #1081286

#TimeUsernameProblemLanguageResultExecution timeMemory
1081286DeathIsAweGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
71 ms7000 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int leftside[200001], rightside[200001]; int32_t main() { int n; cin >> n; vector<int> arr(n); for (int i=0;i<n;i++) { cin >> arr[i]; } leftside[0] = 0; for (int i=1;i<n;i++) { leftside[i] = leftside[i-1] + max(arr[i-1] - arr[i] + 1, (int)0); } rightside[n-1] = 0; for (int i=n-2;i>-1;i--) { rightside[i] = rightside[i+1] + max(arr[i+1] - arr[i] + 1, (int)0); } int ans = INT_MAX, curans; ans = min(leftside[n-1], rightside[0]); for (int i=1;i<n-1;i++) { ans = min(ans, max(leftside[i], rightside[i])); } cout << ans; }

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:25:24: warning: unused variable 'curans' [-Wunused-variable]
   25 |     int ans = INT_MAX, curans;
      |                        ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...