# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
675981 |
2022-12-28T17:44:00 Z |
as111 |
Kas (COCI17_kas) |
C++14 |
|
378 ms |
353228 KB |
#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 |
1 |
Correct |
5 ms |
8916 KB |
Output is correct |
2 |
Correct |
5 ms |
8928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8916 KB |
Output is correct |
2 |
Correct |
6 ms |
8924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8888 KB |
Output is correct |
2 |
Correct |
6 ms |
9648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
10424 KB |
Output is correct |
2 |
Correct |
9 ms |
11192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11180 KB |
Output is correct |
2 |
Correct |
7 ms |
11220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
28372 KB |
Output is correct |
2 |
Correct |
22 ms |
32340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
36320 KB |
Output is correct |
2 |
Correct |
24 ms |
40216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
168 ms |
157624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
269 ms |
235916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
378 ms |
353228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |