|
|
вернуться в форумhelp! I got TLE Here is my program: program p1115; const maxn=100; maxm=10; var ship:array [1..maxn] of longint; long:array [1..maxm] of longint; r:array [1..maxm,0..maxn] of longint; top:array [1..maxm] of longint; m,n:longint; procedure init; var i:longint; begin fillchar(ship,sizeof(ship),0); fillchar(long,sizeof(long),0); fillchar(r,sizeof(r),0); fillchar(top,sizeof(top),0); readln(n,m); for i:=1 to n do readln(ship[i]); for i:=1 to m do readln(long[i]); end; procedure sout; var i,j,k:longint; begin for i:=1 to m do begin j:=1; while (r[i,j]<>0) do inc(j); dec(j); writeln(j); for k:=1 to j do write(r[i,k],' '); writeln; end; end; procedure sort; var i,j,t:longint; begin for i:=1 to (n-1) do for j:=(i+1) to n do if (ship[i]<ship[j]) then begin t:=ship[i]; ship[i]:=ship[j]; ship[j]:=t; end; end; procedure solve(dep:longint); var i:longint; begin for i:=1 to m do if (r[i,0]+ship[dep]<=long[i]) then begin inc(top[i]); r[i,top[i]]:=ship[dep]; inc(r[i,0],ship[dep]); if (dep=n) then begin sout; halt; end else solve(dep+1); r[i,top[i]]:=0; dec(r[i,0],ship[dep]); dec(top[i]); end; end; begin init; sort; solve(1); end. |
|
|