Pagini recente » Cod sursa (job #2255908) | Cod sursa (job #3269998) | Cod sursa (job #3145739) | Cod sursa (job #1441002) | Cod sursa (job #810284)
Cod sursa(job #810284)
#include<stdio.h>
using namespace std;
int n,g,ap[205],v[75005],t[75005];
int main()
{
freopen("ghiozdan.in","r",stdin);
freopen("ghiozdan.out","w",stdout);
int i,q,k,j;
scanf("%d%d",&n,&g);
for(i = 1; i<=n; ++i)
{
scanf("%d\n",&q);
ap[q]++;
}
v[0]=1;
for(i=200;i>=1;i--)
if(ap[i])
for(j=g-i;j>=0;j--)
if(v[j])
for(k=1;k<=ap[i] && j+k*i<=g && !v[j+k*i];k++)
{
v[j+k*i]=v[j]+k;
t[j+k*i]=i;
}
for(i=g;v[i]==0;i--);
printf("%d %d\n",i,v[i]-1);
for(; i!=0; i -= t[i])
printf("%d\n",t[i]);
return 0;
}