Submission #708128

#TimeUsernameProblemLanguageResultExecution timeMemory
708128arcaneBigger segments (IZhO19_segments)C++17
0 / 100
1 ms448 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define mp make_pair #define pb emplace_back int32_t main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, ans = 0, tmp1 = -1e8, tot, pos; cin >> n; int arr[n], smol[n], pref[n + 1]; for (int i = 0; i < n; i++) cin >> arr[i]; pref[0] = 0; for (int i = 0; i < n; i++) pref[i + 1] = pref[i] + arr[i]; for (int i = 0; i < n; i++){ smol[i] = pref[i + 1]; for (int j = i - 1; j >= 0; j--){ if (pref[i + 1] - pref[j + 1] >= smol[j]) smol[i] = min(smol[i], pref[i + 1] - pref[j + 1]); } assert(pref[i + 1] + smol[i] >= tmp1); tmp1 = pref[i + 1] + smol[i]; } tot = pref[n] - smol[n - 1]; pos = n - 1; ans = 1; while (tot){ while (pref[pos + 1] != tot){ pos--; //cerr << pos << '\n'; } tot -= smol[pos]; ans += 1; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...