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>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=300*300+10;
int pl[N];
int a[N],b[N];
void solve(){
int n,m,k;
cin>>n>>m>>k;
int sum1=0,sum2=0,sum3=0;
for(int i=1;i<=n;i++){
cin>>a[i];
sum1+=a[i];
}
for(int i=1;i<=m;i++){
cin>>b[i];
sum2+=b[i];
sum3+=min(n,b[i]);
}
if(sum2<sum1 or sum3<n*k){
cout<<"Impossible\n";
return;
}
for(int i=1;i<=300*300;i++) pl[i]=-1;
for(int i=1;i<=m;i++){
for(int j=300*300;j>=0;j--)
if(j+b[i]<=300*300 and pl[j]!=-1) pl[j+b[i]]=max(pl[j+b[i]],pl[j]+min(b[i],n));
}
for(int i=sum1;i<=300*300;i++){
if(pl[i]>=n*k){
cout<<i-sum1<<"\n";
return;
}
}
}
int main(){
solve();
}
# | 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... |