#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define a first
#define b second
#define pb push_back
int n,m,k;
int aa[301];
int bb[301];
const int li=400*400;
int dp[li];
int su=0;
int ans2=-1;
int brute(int ind,int su2=0,int su3=0){
if(ind==m){
if(su2>=k*n and su3>=su){
if(ans2==-1){
ans2=su3-su;
}
else{
ans2=min(ans2,su3-su);
}
}
}
else{
brute(ind+1,su2,su3);
brute(ind+1,su2+min(bb[ind],n),su3+bb[ind]);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(dp,-1,sizeof(dp));
dp[0]=0;
cin>>n>>m>>k;
int st=0;
for(int i=0;i<n;i++){
cin>>aa[i];
su+=aa[i];
if(aa[i]<k){
st=1;
}
}
int tt=0;
for(int i=0;i<m;i++){
cin>>bb[i];
tt+=bb[i];
}
if(st){
cout<<"Impossible"<<endl;
return 0;
}
if(tt<su){
cout<<"Impossible"<<endl;
return 0;
}
for(int i=0;i<m;i++){
for(int j=li-1;j>=min(bb[i],n);j--){
if(dp[j-min(bb[i],n)]>-1){
dp[j]=max(dp[j],dp[j-min(bb[i],n)]+bb[i]);
}
}
}
int ans5=-1;
for(int i=k*n;i<li;i++){
if(dp[i]>=su){
if(ans5==-1){
ans5=dp[i]-su;
}
else{
ans5=min(ans5,dp[i]-su);
}
}
}
if(ans5==-1){
cout<<"Impossible"<<endl;
return 0;
}
cout<<ans5<<endl;
/* if(k==1){
for(int i=0;i<m;i++){
for(int j=li;j>=bb[i];j--){
dp[j]=max(dp[j],dp[j-bb[i]]);
}
}
int ans=-1;
for(int i=su;i<li;i++){
if(dp[i]){
ans=i-su;
break;
}
}
if(ans==-1){
cout<<"Impossible"<<endl;
}
else{
cout<<ans<<endl;
}
}
else if(m<=15){
brute(0);
if(ans2==-1){
cout<<"Impossible"<<endl;
}
else{
cout<<ans2<<endl;
}
}
else{
}*/
return 0;
}
Compilation message
kitchen.cpp: In function 'int brute(int, int, int)':
kitchen.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
1024 KB |
Output is correct |
2 |
Correct |
51 ms |
896 KB |
Output is correct |
3 |
Correct |
64 ms |
896 KB |
Output is correct |
4 |
Correct |
61 ms |
1024 KB |
Output is correct |
5 |
Correct |
5 ms |
1024 KB |
Output is correct |
6 |
Correct |
45 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
1024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |