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 S 100000
int max(int a, int b) { return a > b ? a : b; }
int main() {
static int dp[S * 2 + 1], dq[S * 2 + 1];
int n, sum;
scanf("%d", &n);
memset(dp, -1, (S * 2 + 1) * sizeof *dp), dp[S] = 0;
sum = 0;
while (n--) {
int c, s;
scanf("%d", &c);
sum += c;
memcpy(dq, dp, (S * 2 + 1) * sizeof *dp);
for (s = 0; s <= S; s++)
if (dp[s] != -1)
dq[s - c] = max(dq[s - c], dp[s] + c), dq[s + c] = max(dq[s + c], dp[s] + c);
memcpy(dp, dq, (S * 2 + 1) * sizeof *dq);
}
printf("%d\n", sum - dp[S] / 2);
return 0;
}
Compilation message (stderr)
kas.c: In function 'main':
kas.c:12:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
kas.c:18:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d", &c);
| ^~~~~~~~~~~~~~~
# | 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... |