Submission #1135143

#TimeUsernameProblemLanguageResultExecution timeMemory
1135143m_bezrutchkaKitchen (BOI19_kitchen)C++20
100 / 100
70 ms100424 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 310; const int INF = 1e9 + 10; int dp[MAXN][MAXN * MAXN]; int a[MAXN], b[MAXN]; int n, m, k; void solve() { cin >> n >> m >> k; int sum_a = 0, sum_b = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum_a += a[i]; if (a[i] < k) { cout << "Impossible\n"; return; } } for (int i = 1; i <= m; i++) { cin >> b[i]; sum_b += b[i]; } for (int i = 0; i <= m; i++) { for (int j = 0; j <= sum_b; j++) { dp[i][j] = -INF; } } dp[0][0] = 0; for (int i = 1; i <= m; i++) { for (int j = 0; j <= sum_b; j++) { dp[i][j] = dp[i - 1][j]; if (j >= b[i]) { dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + min(b[i], n)); } } } for (int r = sum_a; r <= sum_b; r++) { for (int i = 1; i <= m; i++) { if (dp[i][r] >= k * n) { cout << r - sum_a << "\n"; return; } } } cout << "Impossible\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); 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...