제출 #1081263

#제출 시각아이디문제언어결과실행 시간메모리
1081263DeathIsAweGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; int leftside[200001], rightside[200001]; int 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, 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, 0); } int ans = INT_MAX, curans; if (leftside[n-1] > rightside[0]) { ans = rightside[0]; } else { ans = leftside[n-1]; } for (int i=1;i<n-1;i++) { curans = 0; curans += leftside[i-1] + rightside[i+1]; if (arr[i+1] - arr[i] - leftside[i-1] > arr[i-1] - arr[i] - rightside[i+1]) { curans += max(arr[i+1] - arr[i] - leftside[i-1] + 1, 0); } else { curans += max(arr[i-1] - arr[i] - rightside[i+1] + 1, 0); } if (curans < ans) { ans = curans; } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...