Submission #851509

#TimeUsernameProblemLanguageResultExecution timeMemory
851509NeroZeinBigger segments (IZhO19_segments)C++17
13 / 100
1 ms4696 KiB
#include "bits/stdc++.h" #define int long long using namespace std; const int N = 5e5 + 5; int a[N], f[N]; long long pref[N]; pair<int, long long> dp[N]; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } dp[1] = {1, a[1]}; f[1] = 1; for (int i = 2; i <= n; ++i) { int l = f[dp[i - 1].first] - 1, r = i - 1; while (l < r) { int mid = (l + r + 1) / 2; if (dp[mid].second + pref[mid] <= pref[i]) { l = mid; } else { r = mid - 1; } } if (l < f[dp[i - 1].first]) { dp[i] = dp[i - 1]; dp[i].second += a[i]; } else { dp[i].first = dp[l].first + 1; dp[i].second = pref[i] - pref[l]; } } cout << dp[n].first << '\n'; return 0; }
#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...