제출 #854672

#제출 시각아이디문제언어결과실행 시간메모리
854672vjudge1Kitchen (BOI19_kitchen)C++17
9 / 100
17 ms1368 KiB
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> a(n), b(m); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (a[i] < k) { cout << "Impossible"; return 0; } } for (int i = 0; i < m; i++) cin >> b[i]; int limit = *max_element(a.begin(), a.end()); vector<int> aa(limit); for (int i = 0; i < limit; i++) { for (int j = 0; j < n; j++) { aa[i] += a[j] > i; } } sort(b.begin(), b.end(), greater<int>()); int sum = accumulate(b.begin(), b.end(), 0); vector<pair<int, int>> f(sum + 1, make_pair(-1, -1)); f[0] = make_pair(0, 0); int s = 0; auto get = [&](pair<int, int> a, int b) { if (a.first == limit) return make_pair(limit, 0); assert(a.second != aa[a.first]); int x = a.second; a.second += b; if (a.second >= aa[a.first]) { a.second %= aa[a.first]; a.first++; a.second = a.first == limit ? 0 : min(aa[a.first], min(a.second, x)); } return a; }; for (int i = 0; i < m; i++) { for (int j = s; j >= 0; j--) { if (f[j].first == -1) continue; f[j + b[i]] = max(f[j + b[i]], get(f[j], b[i])); } s += b[i]; } for (int i = accumulate(a.begin(),a.end(),0); i <= sum; i++) { if (f[i].first >= k) { cout << i - accumulate(a.begin(), a.end(), 0); return 0; } } cout << "Impossible"; }
#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...