Thứ Ba, 3 tháng 5, 2022

VCOWFLIX PASCAL

const
      fin='vcowflix.INP';
      fon='vcowflix.OUT';
      m=16;
var
   a,x:array[0..m] of longint;
   c,n,max,s,i:longint;
   free:array[1..m] of boolean;
procedure vet(i:byte);
var j:byte;
begin
    for j:=x[i-1]+1 to n do
    begin
        s:=s+a[j]; x[i]:=j;
        if s<=c then
        begin
            if (s>max) then max:=s;
            vet(i+1);
        end; 
        s:=s-a[j];

    end;

end;

begin
     assign(input,fin);reset(input);
     assign(output,fon);rewrite(output);
     read(c,n);
     for i:=1 to n do read(a[i]);
     s:=0;max:=0;
     x[0]:=0;
     vet(1);
     writeln(max);
     close(input);close(output);
end.

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.