Submission #1258844

#TimeUsernameProblemLanguageResultExecution timeMemory
1258844norman165Growing Vegetables is Fun 4 (JOI21_ho_t1)C++20
40 / 100
1096 ms3400 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define int long long #define yes() cout << "YES\n" #define no() cout << "NO\n" using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; const int inf = 1e18; const int mod = 1e9 + 7; const int maxn = 3e5; const int mod1 = 998244353; const int mod2 = 1e18 + 1; const int mod3 = 1e9 + 9; const int mod4 = 333333333; const int mod5 = 200000; const int mod6 = 10007; const int k = 3000; const int w = 1e5; const ld EPS = 1e-8; int LOG = 30; void solve() { int n; cin >> n; vector<int> a(n); for (int& i : a) cin >> i; vector<int> b(n); b[0] = a[0]; for (int i = 1; i < n; i++) b[i] = a[i] - a[i - 1]; int ans = inf; for (int i = 0; i < n; i++) { int cur = 0; int res = 0; for (int j = 0; j <= i; j++) if (b[j] <= 0) { cur += (-b[j] + 1); res += (-b[j] + 1); } for (int j = i + 1; j < n; j++) { if (b[j] >= 0) { int x = b[j] + 1; if (cur >= x) cur -= x; else { res += x - cur; cur = 0; } } } ans = min(ans, res); } cout << ans << "\n"; } signed main() { #ifdef LOCAL #else // freopen("qual" ".in", "r", stdin); // freopen("qual" ".out", "w", stdout); #endif // cout.precision(16); ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...