제출 #1224984

#제출 시각아이디문제언어결과실행 시간메모리
1224984alicecuteKitchen (BOI19_kitchen)C++20
100 / 100
16 ms1096 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); const int N = 300; const int MAXW = N * N; // 300*300 = 90000 int n, m; long long k; cin >> n >> m >> k; vector<long long> a(n), b(m); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; // Nếu có một a[i] < k thì không thể if (*min_element(a.begin(), a.end()) < k) { cout << "Impossible"; return 0; } // Tổng của a[] long long sumA = accumulate(a.begin(), a.end(), 0LL); // DP array: supply[w] = max contribution (tối đa n mỗi lần) // khi dùng tổng khối lượng w từ các b[i]. // Khởi tạo = -INF (ở đây INF = MAXW) vector<long long> supply(MAXW + 1, -MAXW); supply[0] = 0; // Tổng khối lượng có thể có của b[] int bsum = accumulate(b.begin(), b.end(), 0); // Chuyển trạng thái knapsack (0/1, weight = x, value = min(x,n)) for (auto x : b) { for (int w = bsum; w >= 0; --w) { if (w + x <= MAXW) supply[w + x] = max(supply[w + x], supply[w] + min<long long>(x, n)); } } // Tìm w nhỏ nhất sao cho supply[w] >= n*k // và in ra w - sumA for (int w = sumA; w <= MAXW; ++w) { if (supply[w] >= n * k) { cout << (w - sumA); return 0; } } cout << "Impossible"; 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...