Submission #1111149

#TimeUsernameProblemLanguageResultExecution timeMemory
1111149Ghulam_JunaidKitchen (BOI19_kitchen)C++17
100 / 100
273 ms4680 KiB
#include <bits/stdc++.h> using namespace std; const int N = 305; const int SM = N * N; int n, m, k, a[N], b[N], dp_more[SM], dp_less[SM]; int main(){ cin >> n >> m >> k; int need = 0; for (int i = 0; i < n; i ++) cin >> a[i], need += a[i]; for (int i = 0; i < m; i ++) cin >> b[i]; sort(b, b + m); sort(a, a + n); if (a[0] < k){ cout << "Impossible\n"; return 0; } memset(dp_more, -1, sizeof dp_more); memset(dp_less, -1, sizeof dp_less); dp_more[0] = dp_less[0] = 0; set<int> created; created.insert(0); for (int i = 0; i < m; i ++){ for (int sm = SM - 1; sm >= b[i]; sm --){ if (b[i] > n and ~dp_more[sm - b[i]]){ dp_more[sm] = max(dp_more[sm], dp_more[sm - b[i]] + 1); } else if (b[i] <= n and ~dp_less[sm - b[i]]){ dp_less[sm] = max(dp_less[sm], dp_less[sm - b[i]] + 1); created.insert(sm); } } } int ans = 1e9; for (int sm = 0; sm < SM; sm++){ int x = dp_more[sm]; if (x == -1) continue; int left = max((k - x) * n, need - sm); left = max(0, left); auto ub = created.upper_bound(left - 1); if (ub == created.end()) continue; int used = (*ub) + sm; ans = min(ans, used - need); } if (ans == 1e9) cout << "Impossible\n"; else cout << ans << endl; }
#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...