Submission #706127

#TimeUsernameProblemLanguageResultExecution timeMemory
706127becaidoGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
29 ms6988 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second const int SIZE = 2e5 + 5; int n; int a[SIZE], d[SIZE]; ll ans, pre[SIZE], suf[SIZE]; void solve() { cin >> n; FOR (i, 1, n) cin >> a[i]; FOR (i, 1, n) d[i] = a[i] - a[i - 1]; FOR (i, 1, n) pre[i] = pre[i - 1] + max(0, 1 - d[i]); for (int i = n; i >= 1; i--) suf[i] = suf[i + 1] + max(0, d[i] + 1); ans = LLONG_MAX; FOR (i, 1, n) ans = min(ans, max(pre[i], suf[i + 1])); cout << ans << '\n'; } int main() { Waimai; solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...