제출 #567354

#제출 시각아이디문제언어결과실행 시간메모리
567354birthdaycakeKitchen (BOI19_kitchen)C++17
20 / 100
38 ms1056 KiB
#include<bits/stdc++.h> #define endl '\n' #define int long long #define mod 1000000007 #define boost ios_base::sync_with_stdio(false), cin.tie(NULL); using namespace std; int dp[200001],a[20001],b[200001]; signed main(){ boost; int n,m,k,sum = 0; cin >> n >> m >> k; for(int i = 0; i < n; i++){ cin >> a[i]; sum += a[i]; } if(k == 1){ for(int j = 0; j < m; j++) cin >> b[j]; dp[0] = 1; for(int i = 0; i < m; i++){ for(int j = 90000; j >= b[i]; j--){ dp[j] += dp[j - b[i]]; } } for(int i = sum; i <= 90000; i++){ if(dp[i]){ cout << i - sum; return 0; } } cout << "Impossible"; return 0; } for(int j = 0; j < m; j++) cin >> b[j]; for(int i = 0; i < n; i++){ if(a[i] < k){ cout << "Impossible"; return 0; } } if(m < k){ cout << "Impossible"; return 0; } int ans = 1e18; for(int i = 0; i < (1 << m); i++){ priority_queue<pair<int,int>>x; int tot = 0, good = 1; for(int j = 0; j < m; j++){ if(i & (1 << j)){ x.push({b[j],j}); tot += b[j]; } } for(int j = 0; j < n; j++){ int cnt = 0; while(!x.empty() && cnt < k){ auto y = x.top(); x.pop(); if(y.first){ y.first--; if(y.first) x.push({y.first,y.second}); cnt++; }else{ good = 0; } } } if(good){ if(tot - (sum) >= 0) ans = min(ans,tot - sum); } } if(ans == 1e18){ cout << "Impossible"; return 0; } cout << ans; 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...