This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |