Submission #493031

#TimeUsernameProblemLanguageResultExecution timeMemory
493031wiwihoKitchen (BOI19_kitchen)C++14
20 / 100
41 ms460 KiB
#include <bits/stdc++.h> #define printv(a, b) {\ for(auto pv : a) b << pv << " ";\ b << "\n";\ } using namespace std; typedef long long ll; const ll MAX = INT_MAX; void nosol(){ cout << "Impossible\n"; exit(0); } int n, m, k; vector<int> a; vector<int> b; ll sa = 0; const int SZ = 300; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cerr.tie(0); cin >> n >> m >> k; a.resize(n + 1); b.resize(m + 1); ll sb = 0; 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]; sort(a.begin() + 1, a.end(), greater<>()); sort(b.begin() + 1, b.end()); if(k > m || sa > sb){ nosol(); } for(int i = 1; i <= n; i++) if(a[i] < k) nosol(); assert(k == 1); vector<bool> dp(100001); dp[0] = true; for(int i = 1; i <= m; i++){ for(int j = 100000; j >= b[i]; j--){ if(dp[j - b[i]]) dp[j] = true; } } for(int i = sa; i <= 100000; i++){ if(!dp[i]) continue; cout << i - sa << "\n"; return 0; } 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...