#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m, k;
std::cin >> n >> m >> k;
std::vector<int> a(n), b(m);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < m; i++) {
std::cin >> b[i];
}
int64_t sumb = 0;
for (int i = 0; i < m; i++) {
sumb += b[i];
}
if (k == 1) {
int64_t suma = 0;
for (int i = 0; i < n; i++) {
suma += a[i];
}
std::vector<std::vector<bool>> dp(m + 1, std::vector<bool>(sumb + 1, false));
dp[0][0] = 1;
for (int i = 1; i <= m; i++) {
for (int j = 0; j <= sumb; j++) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (j >= b[i - 1]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i - 1]]);
}
}
}
for (int j = suma; j <= sumb; j++) {
if (dp[m][j] == 1) {
std::cout << j - suma << "\n";
return 0;
}
}
std::cout << "Impossible\n";
return 0;
}
assert(false);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
2384 KB |
Output is correct |
2 |
Correct |
53 ms |
1872 KB |
Output is correct |
3 |
Correct |
40 ms |
2128 KB |
Output is correct |
4 |
Correct |
69 ms |
3408 KB |
Output is correct |
5 |
Correct |
68 ms |
3408 KB |
Output is correct |
6 |
Correct |
31 ms |
1616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |