# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
32279 | cscandkswon | Kas (COCI17_kas) | C++14 | 383 ms | 394092 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 <cstdio>
#include <cstdlib>
#include <cstring>
const int MAXN = 503, INF=1e9, ZERO=100000;
int N, A[MAXN], S, ans, D[MAXN][200005];
inline int max(int a, int b) { return (a > b) ? a : b; }
int func(int a, int d) {
if (abs(d - ZERO) > (S / 2)) return -INF;
if (a == N) {
if (d == ZERO) return D[a][d] = 0;
return D[a][d] = -INF;
}
if (D[a][d] != -1) return D[a][d];
D[a][d] = max(func(a + 1, d), max(func(a + 1, d + A[a]) + A[a], func(a + 1, d - A[a])));
return D[a][d];
}
int main() {
memset(D, -1, sizeof D);
int i;
scanf("%d", &N);
for (i = 0; i < N; i++)
scanf("%d", A + i), S+=A[i];
ans = func(0, ZERO);
printf("%d", ans + (S - ans * 2));
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... |
# | 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... |