제출 #1031637

#제출 시각아이디문제언어결과실행 시간메모리
1031637underwaterkillerwhaleGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
17 ms7024 KiB
#include <bits/stdc++.h> #define se second #define fs first #define mp make_pair #define pb push_back #define ll long long #define ii pair<ll,ll> #define ld long double #define SZ(v) (int)v.size() #define ALL(v) v.begin(), v.end() #define bit(msk, i) ((msk >> i) & 1) #define iter(id, v) for(auto id : v) #define rep(i,m,n) for(int i=(m); i<=(n); i++) #define reb(i,m,n) for(int i=(m); i>=(n); i--) using namespace std; mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count()); ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); } const int N = 2e5 + 7; const int Mod = 1e9 + 7; const int szBL = 320; const ll INF = 1e18; const int BASE = 137; int n, Q; ll a[N]; ll pret[N], suft[N]; void solution () { cin >> n; rep (i, 1, n) cin >> a[i]; rep (i, 1, n) { pret[i] = pret[i - 1] + max(0LL, a[i] + 1- a[i + 1]); } reb (i, n, 1) { suft[i] = suft[i + 1] + max(0LL, a[i] + 1 - a[i - 1]); } ll res = INF; rep (i, 0, n) { res = min(res, pret[i] + max(0LL, suft[i + 2] - pret[i])); } cout << res <<"\n"; } #define file(name) freopen(name".inp", "r", stdin); \ freopen(name".out", "w", stdout); int main () { // file("c"); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll num_Test = 1; // cin >> num_Test; while(num_Test--) solution(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...