#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 44;
int n, m, k, s;
int a[N], b[N];
bool dp[N][N][N * N]; //chef, mx, occ, sum
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
s += a[i];
}
int s2 = 0;
for (int i = 0; i < m; ++i) {
cin >> b[i];
s2 += b[i];
}
if (s2 < s) {
cout << "Impossible" << '\n';
return 0;
}
for (int i = 0; i < n; ++i) {
if (a[i] < k) {
cout << "Impossible" << '\n';
return 0;
}
}
dp[k][n][0] = true;
for (int id = 0; id < m; ++id) {
for (int mx = 0; mx <= k; ++mx) {
for (int occ = 0; occ <= n; ++occ) {
for (int sum = s2; sum >= 0; --sum) {
if (!dp[mx][occ][sum]) continue;
int sub = min(b[id], k);
int nmx = mx;
int nocc = (occ - sub + k) % k;
if (nocc >= occ) {
if (mx <= 1) nocc = n, nmx = 0;
else nmx--;
}
if (sum + b[id] <= s2) {
dp[nmx][nocc][sum + b[id]] = true;
}
}
}
}
}
for (int i = s; i <= s2; ++i) {
if (dp[0][n][i]) {
cout << i - s << '\n';
exit(0);
}
}
cout << "Impossible" << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
1076 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |