Submission #403074

#TimeUsernameProblemLanguageResultExecution timeMemory
403074rama_pangKitchen (BOI19_kitchen)C++17
100 / 100
107 ms588 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...