Submission #699075

#TimeUsernameProblemLanguageResultExecution timeMemory
699075jiahngGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
96 ms7188 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef pair<int, int> pi; typedef vector <int> vi; typedef vector <pi> vpi; typedef pair <pi,pi> pipi; typedef pair<pi, ll> pii; typedef set <ll> si; typedef long double ld; #define f first #define s second #define mp make_pair #define FOR(i,s,e) for(int i=s;i<=int(e);++i) #define DEC(i,s,e) for(int i=s;i>=int(e);--i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i,x) for (auto i: x) #define mem(x,i) memset(x,i,sizeof x) #define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define maxn 1000010 #define INF (ll)1e18 #define MOD 1000000007 typedef pair <vi, int> pvi; typedef pair <int,pi> ipi; typedef vector <pii> vpii; #define DEBUG 0 #pragma GCC optimize("trapv") int N,Q,w; int ss[maxn],suff[maxn],A[maxn]; int32_t main(){ cin >> N; FOR(i,1,N) cin >> A[i]; FOR(i,2,N) ss[i] = ss[i-1] + max(0LL, A[i-1] + 1 - A[i]); DEC(i,N-1,1) suff[i] = suff[i+1] + max(0LL, A[i+1] + 1 - A[i]); int ans = INF; FOR(k,1,N) ans = min(ans, max(ss[k],suff[k])); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...