# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
376292 | Halogen | Bigger segments (IZhO19_segments) | C++14 | 1571 ms | 548 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 <bits/stdc++.h>
using namespace std;
#define int long long
int N, lst[500005];
int dp(int x, int sum, int seg) {
int ans = 0;
if (x >= N) {
if (sum >= 0) ans = 0;
else ans = -10234567898765432;
}
else if (sum < 0) ans = dp(x + 1, sum + lst[x], seg + lst[x]);
else ans = max(
dp(x + 1, sum + lst[x], seg + lst[x]),
1 + dp(x + 1, -seg + lst[x], lst[x])
);
// printf("%lld %lld %lld\n", ans, x, seg);
return ans;
}
main() {
scanf("%lld", &N);
for (int i = 0; i < N; i++) scanf("%lld", &lst[i]);
// for (int i = 2; i <= N; i++) lst[i] += lst[i - 1];
printf("%lld\n", dp(0, 0, 0));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |