# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566746 | milisav | Kitchen (BOI19_kitchen) | C++14 | 28 ms | 676 KiB |
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 maxn 305
using namespace std;
int n,m,k;
int a[maxn];
int b[maxn];
int dp[maxn*maxn];
int main() {
scanf("%d %d %d",&n,&m,&k);
int sm=0;
int mn=1e9;
for(int i=1;i<=n;i++) {
scanf("%d",&a[i]);
sm+=a[i];
mn=min(mn,a[i]);
}
for(int i=1;i<=m;i++) scanf("%d",&b[i]);
if(mn<k) {
printf("Impossible");
return 0;
}
for(int i=1;i<maxn*maxn;i++) dp[i]=-1e9;
for(int i=1;i<=m;i++) {
int val=min(n,b[i]);
for(int j=maxn*maxn-1;j>=b[i];j--) {
dp[j]=max(dp[j],dp[j-b[i]]+val);
}
}
int ans=-1;
for(int i=sm;i<maxn*maxn;i++) {
if(dp[i]>=n*k) {
ans=i;
break;
}
}
if(ans==-1) printf("Impossible");
else printf("%d",ans-sm);
return 0;
}
Compilation message (stderr)
# | 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... |