#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 5;
const int maxN = 45;
bool dp[maxN][maxN*maxN][maxN*maxN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n), b(m);
for(int& i : a) {
cin >> i;
}
for(int& i : b) {
cin >> i;
}
int ans = INF;
for(int i : a) {
if (i < k) {
cout << "Impossible\n";
exit(0);
}
}
int time = accumulate(a.begin(), a.end(), 0);
dp[0][0][0] = true;
for(int i = 1; i <= m; i++) {
for(int j = 0; j < maxN*maxN; j++) {
for(int p = 0; p < maxN*maxN; p++) {
dp[i][j][p] |= dp[i-1][j][p];
if (j-b[i-1] < 0 || p-min(n, b[i-1]) < 0) continue;
dp[i][j][p] |= dp[i-1][j-b[i-1]][p-min(n, b[i-1])];
// if (dp[i][j][p]) {
// cout << i << " " << j << " " << p << "\n";
// }
}
}
}
for(int j = time; j < maxN*maxN; j++) {
if (dp[m][j][k*n]) {
ans = min(ans, j-time);
}
}
if (ans == INF) {
cout << "Impossible\n";
} else {
cout << ans << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
8268 KB |
Output is correct |
2 |
Correct |
18 ms |
8272 KB |
Output is correct |
3 |
Incorrect |
17 ms |
8356 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
8268 KB |
Output is correct |
2 |
Correct |
18 ms |
8272 KB |
Output is correct |
3 |
Incorrect |
17 ms |
8356 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
572 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
331 ms |
160712 KB |
Output is correct |
2 |
Correct |
334 ms |
160684 KB |
Output is correct |
3 |
Incorrect |
330 ms |
160732 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
8268 KB |
Output is correct |
2 |
Correct |
18 ms |
8272 KB |
Output is correct |
3 |
Incorrect |
17 ms |
8356 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |