Pagini recente » Cod sursa (job #1527365) | Cod sursa (job #2937338) | Cod sursa (job #1944687) | Cod sursa (job #626677) | Cod sursa (job #18711)
Cod sursa(job #18711)
var
sums:array[0..1,0..75005] of longint;
a:array[1..20000] of longint;
i,j,k,n,s,max,c,r,smax,nrmin:longint;
begin
assign(input,'ghiozdan.in');
reset(input);
readln(n,s);
for i:=1 to n do readln(a[i]);
close(input);
max:=0;
sums[0,0]:=1;
c:=1; r:=0; smax:=1;
for k:=1 to n do
begin
for i:=0 to max do
begin
if (sums[r,i]>0) and (i+a[k]<=s) and ((sums[r,i+a[k]]=0) or (sums[r,i+a[k]]>sums[r,i]+1)) then
begin
sums[c,i+a[k]]:=sums[r,i]+1;
if i+a[k]>max then max:=a[k]+i;
end;
if (sums[c,i]=0) or((sums[r,i]>0) and (sums[r,i]<sums[c,i])) then sums[c,i]:=sums[r,i];
sums[r,i]:=0;
end;
r:=1-r;
c:=1-c;
end;
smax:=0; nrmin:=maxlongint;
for i:=1 to max do
if (i<=s) and (sums[r,i]>0) and (i>smax) then
begin
smax:=i;
nrmin:=sums[r,i];
end;
assign(output,'ghiozdan.out');
rewrite(output);
writeln(smax,' ',nrmin-1);
close(output);
end.