Submission #726844

#TimeUsernameProblemLanguageResultExecution timeMemory
726844TimDeeKitchen (BOI19_kitchen)C++17
51 / 100
81 ms724 KiB
#include <bits/stdc++.h> using namespace std; //#define int long long #define forn(i,n) for(int i=0;i<n;++i) #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define f first #define s second #define pi pair<int,int> #define vii(a,n) vector<int>a(n);forn(i,n)cin>>a[i]; const int inf = 1e9; void solve() { int n,m,k; cin>>n>>m>>k; vii(a,n); vii(b,m); if (k==1) { vector<int> dp(1e5,0); dp[0]=1; int s=0; forn(i,n) s+=a[i]; for(auto&x:b) { for (int i=9e4; i>=0; --i) { dp[i+x]|=dp[i]; } } for (int i=s; i<1e5; ++i) { if (dp[i]) { cout<<i-s; return; } } cout<<"Impossible"; return; } if (m>15) exit(0); if (k>m) { cout<<"Impossible"; return; } forn(i,n) if (a[i]<k) { cout<<"Impossible"; return; } int s=0; for(auto&x:a) s+=x; for(auto&x:b) s-=x; if (s>0) { cout<<"Impossible"; return; } int z=0; for(auto&x:a) z+=x; int ans=inf; for (int mask=0; mask<(1<<m); ++mask) { if (__builtin_popcount(mask) < k) continue; vector<int> f; forn(i,m) if ((mask>>i)&1) f.pb(b[i]); int sum=0; for(auto&x:f) sum+=x; if (sum<z) continue; sort(rall(f)); forn(i,n) { forn(j,k) f[j]--; sort(rall(f)); } if (f.back()<0) continue; ans=min(ans,sum-z); } if (ans==inf) cout<<"Impossible"; else cout<<ans; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#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...