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 LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
#define no cout<<"Impossible"<<endl;return 0;
const int N=200005;
const int INF=1e18;
int32_t main() {
LCBorz;
int n,m,k;cin>>n>>m>>k;
if(m<k){
no;
}
vector<int> a(n),b(m);
int total=0,ta=0,tb=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]<k){
no;
}
total+=a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
ta+=b[i];
}
tb=(k==1?1:k*n);
vector dp(ta+1,vector(tb+1,0));
dp[0][0]=1;
for(int i=0;i<m;i++){
for(int j=ta;j>=b[i];j--){
int tmp=min(b[i],n);
for(int j1=tb;j1>=0;j1--){
dp[j][min(j1+tmp,tb)]|=dp[j-b[i]][j1];
}
}
}
int ans=-1;
for(int i=(k==1?1:total);i<=ta;i++){
for(int j=k*n;ans==-1&&j<=tb;j++){
if(dp[i][j]){
ans=i;break;
}
}
}
if(ans==-1){
no;
}
else{
cout<<ans-total<<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... |