Submission #584344

#TimeUsernameProblemLanguageResultExecution timeMemory
584344tengiz05Kitchen (BOI19_kitchen)C++17
100 / 100
68 ms596 KiB
#include <bits/stdc++.h> using i64 = long long; void chmax(int &a, int b) { if (a < b) a = b; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m, k; std::cin >> n >> m >> k; std::vector<int> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; if (a[i] < k) { std::cout << "Impossible\n"; return 0; } } std::vector<int> b(m); for (int i = 0; i < m; i++) { std::cin >> b[i]; } int sum = std::accumulate(a.begin(), a.end(), 0); int N = std::accumulate(b.begin(), b.end(), 0); std::vector<int> dp(N + 1, -1E9); dp[0] = 0; for (int i = 0; i < m; i++) { for (int j = N - b[i]; j >= 0; j--) { chmax(dp[j + b[i]], dp[j] + std::min(n, b[i])); } } int ans = 1E9; for (int i = sum; i <= N; i++) { if (dp[i] >= n * k) { ans = std::min(ans, i - sum); } } if (ans == 1E9) { std::cout << "Impossible\n"; } else { std::cout << ans << "\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...