#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, 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
73 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |