# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
891604 | alex_2008 | Bigger segments (IZhO19_segments) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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[i].first << "\n";
}