제출 #891602

#제출 시각아이디문제언어결과실행 시간메모리
891602alex_2008Bigger segments (IZhO19_segments)C++14
37 / 100
1564 ms7008 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]); } } } } 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...