# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1109089 | ind1v | Kas (COCI17_kas) | C++11 | 196 ms | 2120 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;
const int N = 5e2 + 5;
const int A = 1e5 + 5;
int n;
int c[N];
int f[2][2 * A];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> c[i];
}
memset(f[0], 0x3f, sizeof(f[0]));
f[0][A] = 0;
for (int i = 1; i <= n; i++) {
memset(f[i & 1], 0x3f, sizeof(f[i & 1]));
for (int j = 0; j < 2 * A; j++) {
f[i & 1][j] = min(f[i & 1][j], f[i & 1 ^ 1][j] + c[i]);
if (j >= c[i]) {
f[i & 1][j] = min(f[i & 1][j], f[i & 1 ^ 1][j - c[i]]);
}
if (j + c[i] < 2 * A) {
f[i & 1][j] = min(f[i & 1][j], f[i & 1 ^ 1][j + c[i]]);
}
}
}
long long sum = accumulate(c + 1, c + n + 1, 0LL);
cout << (sum - f[n & 1][A]) / 2 + f[n & 1][A] << '\n';
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... |