#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("test33.in", "r", stdin);
//freopen("test01.out", "w", stdout);
int n, m, k, a[301], b[301], sa = 0, sb = 0;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sa += a[i];
}
for (int i = 1; i <= m; i++) {
cin >> b[i];
sb += b[i];
}
if (m < k || *min_element(a + 1, a + 1 + n) < k) {
cout << "Impossible\n";
return 0;
}
// dp[i][j]: số giờ tối đa có thể lấp khối đa dạng khi chọn tập đầu bếp từ 1->i với tổng giờ thuê j
int dp[301][301 * 300 + 1];
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= m; i++)
for (int j = 0; j <= sb; j++) {
dp[i][j] = dp[i - 1][j];
if (j >= b[i] && dp[i - 1][j - b[i]] != -1)
dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + min(b[i], n));
}
for (int j = sa; j <= sb ; j++)
if (dp[m][j] >= n * k) {
cout << j - sa << "\n";
return 0;
}
cout << "Impossible\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |