제출 #746029

#제출 시각아이디문제언어결과실행 시간메모리
746029vjudge1Kitchen (BOI19_kitchen)C++14
31 / 100
29 ms300 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int n, m, k; cin >> n >> m >> k; vector<int> a(n), b(m); int csum = 0, mmm = k; for(int i = 0; i < n; i++){ cin >> a[i]; csum += a[i]; mmm = min(mmm, a[i]); } for(int i = 0; i < m; i++){ cin >> b[i]; } if(mmm < k){ cout << "Impossible\n"; return 0; } int ans = INT_MAX; int ketto[20]; ketto[0] = 1; for(int i = 1; i < 20; i++){ ketto[i] = 2 * ketto[i - 1]; } for(int i = 0; i < ketto[m]; i++){ int sum = 0; for(int j = 0; j < m; j++){ if(ketto[j] & i){ sum += b[j]; } } if(csum > sum){ continue; } priority_queue<int> pq; for(int j = 0; j < m; j++){ if(ketto[j] & i){ pq.push(b[j]); } } int n1 = n; vector<int> vf; int errar = false; while(n1--){ int k1 = k; vf.clear(); while(k1--){ if(pq.size() > 0 && pq.top() > 0){ vf.push_back(pq.top() - 1); pq.pop(); } else{ errar = true; } } for(int e : vf){ if(e > 0){ pq.push(e); } } } if(!errar){ ans = min(ans, sum - csum); continue; } } if(ans != INT_MAX) cout << ans << endl; else cout << "Impossible\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...