#include <bits/stdc++.h>
using namespace std;
const int MAX_S = 305 * 305;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, M, K;
cin >> N >> M >> K;
vector<int> A(N), B(M);
for (int &v : A) {
cin >> v;
if (v < K) {
cout << "Impossible\n";
exit(0);
}
}
for (int &v : B) {
cin >> v;
}
int SA = accumulate(A.begin(), A.end(), 0);
bitset<MAX_S> bs;
vector<int> dp(MAX_S, -1e9);
dp[0] = 0;
bs[0] = 1;
for (int i = 0; i < M; i++) {
if (B[i] < N) {
bs |= bs << B[i];
} else {
vector<int> new_dp = dp;
for (int j = 0; j + B[i] < MAX_S; j++) {
new_dp[j + B[i]] = max(new_dp[j + B[i]], dp[j] + 1);
}
dp = new_dp;
}
}
vector<int> reachable;
for (int i = 0; i < MAX_S; i++) {
if (bs[i]) {
reachable.push_back(i);
}
}
int ans = INT_MAX;
for (int j = 0; j < MAX_S; j++) {
if (dp[j] >= 0) {
auto it = lower_bound(reachable.begin(), reachable.end(), max(N * (K - dp[j]), SA - j));
if (it != reachable.end()) {
ans = min(ans, *it + j - SA);
}
}
}
if (ans == INT_MAX) {
cout << "Impossible\n";
} else {
cout << ans << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1000 KB |
Output is correct |
2 |
Correct |
2 ms |
1000 KB |
Output is correct |
3 |
Correct |
1 ms |
1000 KB |
Output is correct |
4 |
Correct |
1 ms |
1000 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
352 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
1008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1000 KB |
Output is correct |
2 |
Correct |
2 ms |
1000 KB |
Output is correct |
3 |
Correct |
1 ms |
1000 KB |
Output is correct |
4 |
Correct |
1 ms |
1000 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
352 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
1008 KB |
Output is correct |
9 |
Correct |
5 ms |
1000 KB |
Output is correct |
10 |
Correct |
5 ms |
1000 KB |
Output is correct |
11 |
Correct |
3 ms |
1012 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
980 KB |
Output is correct |
2 |
Correct |
2 ms |
1108 KB |
Output is correct |
3 |
Correct |
3 ms |
1128 KB |
Output is correct |
4 |
Correct |
14 ms |
1136 KB |
Output is correct |
5 |
Correct |
5 ms |
1384 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1000 KB |
Output is correct |
2 |
Correct |
3 ms |
1000 KB |
Output is correct |
3 |
Correct |
3 ms |
1012 KB |
Output is correct |
4 |
Correct |
2 ms |
1104 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1000 KB |
Output is correct |
2 |
Correct |
2 ms |
1000 KB |
Output is correct |
3 |
Correct |
1 ms |
1000 KB |
Output is correct |
4 |
Correct |
1 ms |
1000 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
352 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
1008 KB |
Output is correct |
9 |
Correct |
5 ms |
1000 KB |
Output is correct |
10 |
Correct |
5 ms |
1000 KB |
Output is correct |
11 |
Correct |
3 ms |
1012 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
980 KB |
Output is correct |
15 |
Correct |
2 ms |
1108 KB |
Output is correct |
16 |
Correct |
3 ms |
1128 KB |
Output is correct |
17 |
Correct |
14 ms |
1136 KB |
Output is correct |
18 |
Correct |
5 ms |
1384 KB |
Output is correct |
19 |
Correct |
1 ms |
852 KB |
Output is correct |
20 |
Correct |
5 ms |
1000 KB |
Output is correct |
21 |
Correct |
3 ms |
1000 KB |
Output is correct |
22 |
Correct |
3 ms |
1012 KB |
Output is correct |
23 |
Correct |
2 ms |
1104 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
42 ms |
1000 KB |
Output is correct |
26 |
Correct |
28 ms |
1000 KB |
Output is correct |
27 |
Correct |
12 ms |
1000 KB |
Output is correct |
28 |
Correct |
29 ms |
1000 KB |
Output is correct |
29 |
Correct |
29 ms |
1000 KB |
Output is correct |
30 |
Correct |
19 ms |
1100 KB |
Output is correct |