# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344582 | Nurlykhan | Bigger segments (IZhO19_segments) | C++17 | 26 ms | 1388 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>
#define ll long long
using namespace std;
const int N = (int)500 + 10;
const int mod = (int)1e9 + 7;
int n;
int a[N];
ll pref[N];
ll get_sum(int l, int r) {
return pref[r + 1] - pref[l];
}
int dp[N][N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
pref[i] = pref[i - 1] + a[i];
}
for (int r0 = 0; r0 <= n; r0++) {
for (int r1 = r0 + 1; r1 <= n; r1++) {
dp[r0][r1] = -mod;
}
dp[0][r0] = 0;
}
for (int r0 = 0; r0 <= n; r0++) {
for (int r1 = r0 + 1; r1 <= n; r1++) {
for (int r2 = r1 + 1; r2 <= n; r2++) {
if (2 * pref[r1] - pref[r0] <= pref[r2]) {
dp[r1][r2] = max(dp[r1][r2], dp[r0][r1] + 1);
}
}
}
}
int ans = 0;
for (int r0 = 0; r0 <= n; r0++)
ans = max(ans, dp[r0][n]);
cout << ans + 1;
return 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... |