제출 #1181526

#제출 시각아이디문제언어결과실행 시간메모리
1181526qwushaKitchen (BOI19_kitchen)C++20
51 / 100
20 ms1296 KiB
#include <bits/stdc++.h> using namespace std; /* #pragma GCC optimize("O3") #include <bitset> #pragma GCC target("avx2")*/ #define fi first #define se second #define int long long typedef long long ll; typedef long double ld; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); int inf = 1e15; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, k; cin >> n >> m >> k; vector<int> a(n); vector<int> b(m); for (int i =0 ; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } int sum = 0; bool ok = 1; for (int i = 0; i < n; i++) { sum += a[i]; if (a[i] < k) ok = 0; } vector<int> s; for (int i = 0; i < m; i++) { if (b[i] >= k) s.push_back(b[i]); } if (!ok) { cout << "Impossible" << '\n'; return 0; } sort(s.rbegin(), s.rend()); vector<int> dp(300 * 300 + 100, -1); dp[0] = 0; int mini = inf; for (int i = 0; i < s.size(); i++) { int val = s[i]; for (int j = dp.size() - 1; j >= val; j--) { if (dp[j - val] != -1) dp[j] = max(dp[j], dp[j - val] + 1); } int num = 1; int cur = s[i]; int ind = i - 1; while (cur < n && ind >= 0) { cur += s[ind]; num++; ind--; } for (int j = sum; j < dp.size(); j++) { if (dp[j] >= k + num - 1) { mini = j; break; } } } if (mini == inf) { cout << "Impossible" << '\n'; } else { cout << mini - sum << '\n'; } }
#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...