제출 #1282226

#제출 시각아이디문제언어결과실행 시간메모리
1282226kaiboyGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
16 ms4340 KiB
#include <algorithm> #include <iostream> using namespace std; const int N = 200000; const long long INF = 0x3f3f3f3f3f3f3f3fLL; int aa[N]; long long pp[N], qq[N]; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); int n; cin >> n; for (int i = 0; i < n; i++) cin >> aa[i]; long long p = 0; for (int i = 1; i < n; i++) pp[i] = p += max(aa[i - 1] + 1 - aa[i], 0); long long q = 0; for (int i = n - 2; i >= 0; i--) qq[i] = q += max(aa[i + 1] + 1 - aa[i], 0); long long ans = INF; for (int i = 0; i < n; i++) ans = min(ans, max(pp[i], qq[i])); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...