#include <bits/stdc++.h>
using namespace std;
const int N = 300;
int n, m, k, a[N], b[N];
bitset<N * N> dp[N * N], save[N * N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
bool ok = 1;
int s = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] < k)
ok = 0;
s += a[i];
}
for (int i = 0; i < m; i++)
cin >> b[i];
if (!ok) {
cout << "Impossible";
return 0;
}
dp[0][0] = 1;
for (int i = 0; i < m; i++) {
for (int j = 0; j <= m * n; j++)
save[j] = dp[j];
for (int j = 0; j <= m * n; j++)
dp[j + min(b[i], n)] |= (save[j] << b[i]);
}
int ans = INT_MAX;
for (int i = n * k; i <= n * m; i++)
for (int j = s; j <= m * N; j++)
if (dp[i][j])
ans = min(ans, j);
if (ans == INT_MAX)
cout << "Impossible";
else
cout << ans - s;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
7 ms |
18516 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
7 ms |
18516 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
4984 KB |
Output is correct |
9 |
Correct |
7 ms |
5976 KB |
Output is correct |
10 |
Correct |
4 ms |
5464 KB |
Output is correct |
11 |
Correct |
11 ms |
9308 KB |
Output is correct |
12 |
Correct |
22 ms |
13900 KB |
Output is correct |
13 |
Correct |
292 ms |
104784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
41 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
26692 KB |
Output is correct |
2 |
Correct |
175 ms |
26204 KB |
Output is correct |
3 |
Correct |
241 ms |
34652 KB |
Output is correct |
4 |
Correct |
281 ms |
39000 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
7 ms |
18516 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
4984 KB |
Output is correct |
9 |
Correct |
7 ms |
5976 KB |
Output is correct |
10 |
Correct |
4 ms |
5464 KB |
Output is correct |
11 |
Correct |
11 ms |
9308 KB |
Output is correct |
12 |
Correct |
22 ms |
13900 KB |
Output is correct |
13 |
Correct |
292 ms |
104784 KB |
Output is correct |
14 |
Runtime error |
41 ms |
262144 KB |
Execution killed with signal 9 |
15 |
Halted |
0 ms |
0 KB |
- |