Submission #891605

#TimeUsernameProblemLanguageResultExecution timeMemory
891605alex_2008Bigger segments (IZhO19_segments)C++14
0 / 100
4 ms4700 KiB
#include <iostream> typedef long long ll; using namespace std; const int N = 5e5 + 10; ll pref[N]; pair <ll, ll> dp[N]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> pref[i]; pref[i] += pref[i - 1]; } dp[0] = { 0, 0 }; for (int i = 1; i <= n; i++) { dp[i] = { dp[i - 1].first, dp[i - 1].second + pref[i] - pref[i - 1] }; for (int j = 0; j < i; j++) { if (dp[j].second <= pref[i] - pref[j]) { if (dp[j].first + 1 > dp[i].first || (dp[j].second < dp[i].second && dp[j].first + 1 == dp[i].first)) { dp[i] = make_pair(dp[j].first + 1, pref[i] - pref[j]); } } } if (dp[i].second < dp[i - 1].second) throw "esim"; } cout << dp[n].first << "\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...