Submission #984406

#TimeUsernameProblemLanguageResultExecution timeMemory
984406OAleksaKitchen (BOI19_kitchen)C++14
29 / 100
79 ms2136 KiB
#include <bits/stdc++.h> #define f first #define s second using namespace std; const int N = 310; int n, m, k, a[N], b[N]; pair<int, int> dp[N * N], ndp[N * N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n >> m >> k; for (int i = 1;i <= n;i++) cin >> a[i]; sort(a + 1, a + n + 1); for (int i = 1;i <= m;i++) cin >> b[i]; if (m < k || a[1] < k) cout << "Impossible"; else { dp[0] = {1, 0}; for (int i = 1;i <= m;i++) { for (int j = 0;j < N * N;j++) { if (j < b[i]) ndp[j] = dp[j]; else { ndp[j].f = max(dp[j - b[i]].f, dp[j].f); ndp[j].s = max(dp[j - b[i]].s + 1, dp[j].s); } } for (int i = 0;i < N * N;i++) dp[i] = ndp[i], ndp[i] = {0, 0}; } int s = 0, ans = 1e9; for (int i = 1;i <= n;i++) s += a[i]; for (int i = N * N - 1;i >= s;i--) { if (dp[i].f && dp[i].s >= k) ans = i - s; } if (ans == 1e9) cout << "Impossible\n"; else 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...