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 <stdio.h>
#include <string.h>
#define N 5000
int max(int a, int b) { return a > b ? a : b; }
int main() {
static int aa[N + 1], dp[N + 1][N + 1], dq[N + 1];
int n, i, j, k, x, c, ans;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &aa[i]);
aa[i] += aa[i - 1];
}
for (i = 1; i <= n; i++)
dp[0][i] = 0;
for (j = 1; j <= n; j++) {
for (i = 0; i < j; i++)
dq[i] = dp[i][j];
for (i = 1; i < j; i++)
dq[i] = max(dq[i], dq[i - 1]);
x = 0, c = 0;
for (i = j - 1, k = j + 1; k <= n; k++) {
dp[j][k] = x;
while (i >= 0 && aa[i] + aa[k] > aa[j] * 2)
i--;
if (i > 0 && aa[i] + aa[k] == aa[j] * 2)
x = max(x, dq[i - 1] + ++c);
}
}
ans = 0;
for (i = 0; i < n; i++)
ans = max(ans, dp[i][n]);
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
cigle.c: In function 'main':
cigle.c:12:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
cigle.c:14:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# | 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... |