Pagini recente » Profil Gergo123 | Diferente pentru preoni-2007/runda-3/solutii intre reviziile 24 si 53 | Istoria paginii preoji2017 | Profil usureluflorian | Cod sursa (job #19147)
Cod sursa(job #19147)
#include <stdio.h>
#define inf 31313
int n, s;
short best[80000], nr[300], a[22222];
char t[80000];
int main()
{
freopen("ghiozdan.in", "r", stdin);
freopen("ghiozdan.out", "w", stdout);
int i,j,k;
scanf("%d %d", &n, &s);
for (i=0; i<n; i++)
scanf("%d", &k), nr[k]++;
n=0;
for (i=250; i>0; i--)
for (j=0; j<nr[i]; j++) a[n++]=i;
for (i=1; i<=s; i++) best[i]=inf;
int last=0;
for (i=0; i<n; i++){
k=a[i];
last+=k;
if (last>s) last=s;
for (j=last; j>=k; j--)
if (best[j-k]<best[j]-1) best[j]=best[j-k]+1, t[j]=k;
if (best[s]<inf) break;
}
while (best[s]==inf) s--;
printf("%d %d\n", s, best[s]);
while (s) printf("%d\n", t[s]), s-=t[s];
return 0;
}