제출 #983995

#제출 시각아이디문제언어결과실행 시간메모리
983995vjudge1Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> #define ft first #define sd second #define pb push_back #define nl "\n" #define int ll typedef long long ll; typedef long double ld; using namespace std; const int N = 1000100; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; while(T--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int dp[n], dp1[n]; dp[0] = 0; dp1[0] = 0; for (int i = 1; i < n; i++) { dp[i] = dp[i - 1]; if (a[i - 1] >= a[i]) { dp[i] += (a[i - 1] - a[i] + 1); } } reverse(a, a + n); for (int i = 1; i < n; i++) { dp1[i] = dp1[i - 1]; if (a[i - 1] >= a[i]) { dp1[i] += (a[i - 1] - a[i] + 1); } } int mn = 1e18; for (int i = 0; i < n; i++) { mn = min( mn, dp[i] + dp1[n - i - 1]); } cout << mn; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...