Submission #566866

#TimeUsernameProblemLanguageResultExecution timeMemory
566866inluminasKitchen (BOI19_kitchen)C++17
100 / 100
54 ms680 KiB
#include"bits/stdc++.h" using namespace std; #define ll long long #define endl "\n" #define fastio ios_base::sync_with_stdio(false) #define inf LLONG_MAX #define l first #define r second const int lmt=90001; int val[lmt]; int main(){ fastio; int n,m,k; cin>>n>>m>>k; int a[n+1],b[m+1]; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=m;i++) cin>>b[i]; sort(a+1,a+n+1); sort(b+1,b+m+1); ll sum=0; for(int i=1;i<=n;i++){ if(a[i]<k){ cout<<"Impossible"<<endl; return 0; } sum+=a[i]; } for(int i=1;i<lmt;i++) val[i]=-1; for(int i=1;i<=m;i++){ for(int j=lmt-1;j>=0;j--){ if(val[j]==-1 || j+b[i]>=lmt) continue; val[j+b[i]]=max(val[j+b[i]],val[j]+min(n,b[i])); } } ll ans=inf; for(int i=sum;i<lmt;i++){ if(val[i]<n*k) continue; ans=min(ans,i-sum); } if(ans==inf){ cout<<"Impossible"<<endl; return 0; } cout<<ans<<endl; 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...