이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |