# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1268930 | hoa208 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++20 | 15 ms | 3500 KiB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
const ll mod = 1e9 + 7;
const ll INF = 1e18;
//--------------------------------------------------------------------
const ll N = 2e5 + 10;
ll n, a[N], b[N];
void hbmt() {
cin >> n;
FOR(i, 1, n) {
cin >> a[i];
}
ll pre = a[1];
FOR(i, 2, n) {
ll k = pre - a[i] + 1;
k = max(0LL, k);
b[i] = b[i - 1] + k;
pre = a[i];
}
ll ans = b[n];
pre = a[n];
ll cnt = 0;
FORD(i, n - 1, 1) {
ll k = pre - a[i] + 1;
k = max(0LL, k);
cnt += k;
ans = min(ans, max(cnt, b[i]));
pre = a[i];
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
#define NAME "hbmt"
if(fopen(NAME".inp", "r")) {
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
//int t;cin>>t;while(t--)
hbmt();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |