Submission #426544

#TimeUsernameProblemLanguageResultExecution timeMemory
426544HideoGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
37 ms7384 KiB
#include <bits/stdc++.h> using namespace std; #define all(s) s.begin(), s.end() #define int long long #define fr first #define sc second #define pb push_back #define mk make_pair const int N = 2e5 + 7; const int INF = 1e9 + 7; int a[N], sf[N], pr[N], m[N]; int n, ans; main (){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i]; } for (int i = n - 1; i >= 1; i--){ sf[i] = sf[i + 1] + max(0ll, a[i + 1] - a[i] + 1); m[i] = max(m[i], a[i + 1] - a[i] + 1); } ans = sf[1]; for (int i = 2; i < n; i++){ pr[i] = pr[i - 1] + max(0ll, a[i - 1] - a[i] + 1); ans = min(ans, max(pr[i], sf[i])); } pr[n] = pr[n - 1] + max(0ll, a[n - 1] - a[n] + 1); ans = min(ans, pr[n]); cout << ans << endl; }

Compilation message (stderr)

Main.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   17 | main (){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...