제출 #1318035

#제출 시각아이디문제언어결과실행 시간메모리
1318035fuad_cr7Growing Vegetables is Fun 4 (JOI21_ho_t1)C++20
0 / 100
0 ms336 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define tiii tuple<int, int, int> #define arrs arr + 1, arr + n + 1 #define cems cem + 1, cem + n + 1 #define vts vt.begin(), vt.end() #define vrs vr.begin(), vr.end() #define as a.begin(), a.end() #define bs b.begin(), b.end() #define ull unsigned long long #define pri priority_queue #define pii pair<int, int> #define lb lower_bound #define ub upper_bound #define dl double long #define pb push_back #define S second #define db double #define F first #define Ronaldo while const int MAX = 2e5 + 5, inf = 1e18; void cr7() { int n; cin >> n; int arr[n + 1]; for (int i = 1; i <= n; i++) cin >> arr[i]; int a[n + 5], b[n + 5]; a[1] = 0, b[n] = 0; for (int i = 2; i <= n; i++) a[i] = a[i - 1] + max(arr[i - 1] - arr[i] + 1, 0ll); for (int i = n - 1; i >= 1; i--) b[i] = b[i + 1] + max(arr[i + 1] - arr[i] + 1, 0ll); int min_val = inf; for (int i = 1; i <= n; i++){ min_val = min(min_val, a[i] + b[i]); //cout << b[i] << " "; } cout << min_val << endl; } signed main(){ int GOAT = 1; //cin >> GOAT; Ronaldo (GOAT--){ cr7(); } } /* $$$$$$$$\ $$$$$$$$\ $$ _____|\____$$ | $$ | $$ / $$$$$\ $$ / $$ __| $$ / $$ | $$ / $$$$$$$$\ $$$$$$$$\ \________|\________| */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...