# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
216132 | MKopchev | Kitchen (BOI19_kitchen) | C++14 | 17 ms | 768 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>
using namespace std;
const int nmax=3e2+42,inf=1e9;
void no()
{
printf("Impossible");
exit(0);
}
int take_min(int a,int b)
{
if(a==-1)return b;
return min(a,b);
}
int filled[nmax*nmax];
int n,m,k;
int main()
{
scanf("%i%i%i",&n,&m,&k);
int sum=0,dish;
for(int i=1;i<=n;i++)
{
scanf("%i",&dish);
if(dish<k)no();
sum=sum+dish;
}
for(int i=1;i<nmax*nmax;i++)filled[i]=-inf;
int chef,ret=-1,total=0;
for(int i=1;i<=m;i++)
{
scanf("%i",&chef);
total=total+chef;
for(int bought=total;bought>=chef;bought--)
{
int can_buy=min(n,chef);
filled[bought]=max(filled[bought],filled[bought-chef]+can_buy);
}
//for(int bought=0;bought<=total;bought++)cout<<filled[bought]<<" ";cout<<endl;
}
if(total<sum)no();
//cout<<"sum= "<<sum<<endl;
for(int i=sum;i<=total;i++)
if(filled[i]>=k*n)ret=take_min(ret,i-sum);
if(ret==-1)no();
printf("%i\n",ret);
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... |