이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#define MAXN 500
#define MAX 100000
using namespace std;
int N;
int notes[MAXN + 5];
int dp[MAXN + 5][2*MAX + 5]; // for first i banknotes, difference between 2 sums + MAX, diff<MAX means negative
int main() {
cin >> N;
int total = 0;
for (int i = 1; i <= N; i++) {
cin >> notes[i];
total += notes[i];
fill(dp[i], dp[i] + 2*MAX, MAX + 1);
}
for (int i = 0; i <= N; i++) fill(dp[i], dp[i] + 2*MAX, MAX + 1);
dp[0][MAX] = 0;
for (int i = 0; i < N; i++) {
for (int k = -total; k <= total; k++) {
int j = k + MAX;
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + notes[i + 1]); // add to remaining
dp[i + 1][j + notes[i + 1]] = min(dp[i + 1][j + notes[i + 1]], dp[i][j]); // add to first person
dp[i + 1][j - notes[i + 1]] = min(dp[i + 1][j - notes[i + 1]], dp[i][j]); // add to second
}
}
cout << ((total-dp[N][MAX])/2+dp[N][MAX]);
}
# | 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... |