#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, M, K;
cin >> N >> M >> K;
vector<int> A(N), B(M);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
for (int i = 0; i < M; i++) {
cin >> B[i];
}
for (int i = 0; i < N; i++) {
if (A[i] < K) {
cout << "Impossible\n";
return 0;
}
}
// There are N * K special slots, and sum(A) - N * K non-special slots
// Each chef can contribute to at most N special slots
// dp[chef][total_sum] = max number of special slots we can fill, if
// we have "total_sum" working chef hours.
// Time complexity: O(M^2 B_max).
int S = accumulate(begin(B), end(B), 0);
vector<int> dp(S + 1, -1e9);
dp[0] = 0;
for (int i = 0; i < M; i++) {
for (int j = S - B[i]; j >= 0; j--) {
dp[j + B[i]] = max(dp[j + B[i]], dp[j] + min(N, B[i]));
}
}
for (int i = accumulate(begin(A), end(A), 0); i <= S; i++) {
if (dp[i] >= N * K) {
cout << i - accumulate(begin(A), end(A), 0) << '\n';
return 0;
}
}
cout << "Impossible\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
460 KB |
Output is correct |
2 |
Correct |
56 ms |
460 KB |
Output is correct |
3 |
Correct |
61 ms |
460 KB |
Output is correct |
4 |
Correct |
107 ms |
588 KB |
Output is correct |
5 |
Correct |
105 ms |
588 KB |
Output is correct |
6 |
Correct |
44 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
72 ms |
460 KB |
Output is correct |
15 |
Correct |
56 ms |
460 KB |
Output is correct |
16 |
Correct |
61 ms |
460 KB |
Output is correct |
17 |
Correct |
107 ms |
588 KB |
Output is correct |
18 |
Correct |
105 ms |
588 KB |
Output is correct |
19 |
Correct |
44 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
53 ms |
460 KB |
Output is correct |
26 |
Correct |
66 ms |
556 KB |
Output is correct |
27 |
Correct |
20 ms |
428 KB |
Output is correct |
28 |
Correct |
54 ms |
460 KB |
Output is correct |
29 |
Correct |
74 ms |
588 KB |
Output is correct |
30 |
Correct |
105 ms |
568 KB |
Output is correct |