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 int long long
#define endl "\n"
using namespace std;
vector<int>a;
vector<int>b;
vector<int>contribution;
int n,m,k;
int total=0;
int sum=0;
int c=0;
int c1;
int smallest=INT_MAX;
void dp(int i){
if(i>=m)return;
if(sum>smallest){
return;
}
sum+=b[i];
c+=contribution[i];
if(c>=c1&&sum>=total){
smallest=min(smallest,sum);
if(sum==smallest){
sum-=b[i];
c-=contribution[i];
return;
}
}
dp(i+1);
sum-=b[i];
c-=contribution[i];
dp(i+1);
}
signed main(){
cin>>n>>m>>k;
c1=n*k;
a.resize(n);
b.resize(m);
contribution.resize(m);
int cont=0;
int s=0;
bool flag=false;
for(int i=0;i<n;i++){
cin>>a[i];
total+=a[i];
if(a[i]<k){
flag=true;
}
}
for(int i=0;i<m;i++){
cin>>b[i];
s+=b[i];
contribution[i]=min(n,b[i]);
cont+=contribution[i];
}
if(flag){
cout<<"Impossible\n";
return 0;
}
if((n*k)>cont){
cout<<"Impossible\n";
return 0;
}
if(total>s){
cout<<"Impossible\n";
return 0;
}
dp(0);
cout<<smallest-total<<endl;
}
# | 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... |