Submission #1175911

#TimeUsernameProblemLanguageResultExecution timeMemory
1175911TsaganaGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
15 ms5132 KiB
#include<bits/stdc++.h> #define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie(); #define all(x) x.begin(), x.end() #define int long long #define pq priority_queue #define eb emplace_back #define lb lower_bound #define ub upper_bound #define pb push_back #define pp pop_back #define F first #define S second using namespace std; int n; int a[200010]; int h1[200010]; int h2[200010]; int ans = 1e18; void solve () { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n + 1; i++) h1[i] = h1[i-1] + max(0LL, a[i-1] - a[i] + 1); for (int i = n; i >= 1 - 1; i--) h2[i] = h2[i+1] + max(0LL, a[i+1] - a[i] + 1); for (int i = 1; i <= n; i++) ans = min(ans, max(h1[i], h2[i])); cout << ans; } signed main() {IOS solve(); return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...