Submission #918005

#TimeUsernameProblemLanguageResultExecution timeMemory
918005borisAngelovKitchen (BOI19_kitchen)C++17
100 / 100
68 ms111696 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 305; const int maxsum = maxn * maxn; const int inf = 1e9; int n, m, k; int a[maxn]; int b[maxn]; int dp[maxn][maxsum]; void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n >> m >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= m; ++i) { cin >> b[i]; } for (int i = 1; i <= n; ++i) { if (a[i] < k) { cout << "Impossible" << endl; return 0; } } for (int i = 0; i < maxn; ++i) { for (int j = 0; j < maxsum; ++j) { dp[i][j] = -inf; } } int sumB = 0; for (int i = 1; i <= m; ++i) { sumB += b[i]; } int sumA = 0; for (int i = 1; i <= n; ++i) { sumA += a[i]; } if (sumA > sumB) { cout << "Impossible" << endl; return 0; } dp[0][0] = 0; for (int pos = 1; pos <= m; ++pos) { for (int sum = 0; sum <= sumB; ++sum) { dp[pos][sum] = dp[pos - 1][sum]; if (sum >= b[pos]) { dp[pos][sum] = max(dp[pos][sum], min(b[pos], n) + dp[pos - 1][sum - b[pos]]); } } } for (int i = sumA; i <= sumB; ++i) { if (dp[m][i] >= n * k) { cout << i - sumA << endl; return 0; } } cout << "Impossible" << endl; 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...