Pagini recente » Cod sursa (job #672289) | Cod sursa (job #506564) | Cod sursa (job #1287890) | Cod sursa (job #985756) | Cod sursa (job #109843)
Cod sursa(job #109843)
var f,g:text;
st:array[1..1000] of integer;
i,j,n,x,poz,a:longint;
begin
assign(f,'economie.in'); reset(f);
assign(g,'economie.out'); rewrite(g);
readln(f,n);
poz:=0;
for i := 1 to n do begin
readln(f,a);
x:=a;
if poz <> 0 then begin
for j := poz downto 1 do begin
while x-st[j] >= 0 do
x:=x-st[j];
if x <= 0 then begin
if (x<0) and (j = 1) then begin
inc(poz);
st[poz]:=a;
break;
end;
if x=0 then break;
end else if (x>0) then
if j=1 then begin
inc(poz);
st[poz]:=a;
end;
end;
end else
begin inc(poz); st[poz]:=a; end;
end;
writeln(g,poz);
for i := 1 to poz do writeln(g,st[i]);
close(f);
close(g);
end.