VCOWFLIX - Đi xem phim

Tác giả: flashmt

Ngôn ngữ: Pascal

var n,i,j,re,c,s:longint;
    a:array[1..16] of longint;
begin
     read(c,n);
     for i:=1 to n do read(a[i]);
     for i:=1 to 1 shl n-1 do
     begin
           s:=0;
           for j:=1 to n do
                if i shr (j-1) and 1=1 then s:=s+a[j];
           if (s<=c) and (s>re) then re:=s;
           if re=c then break;
     end;
     writeln(re);
end.

Download