Pagini recente » Cod sursa (job #2768245) | Cod sursa (job #1416753) | Cod sursa (job #2531107) | Cod sursa (job #3159182) | Cod sursa (job #553111)
Cod sursa(job #553111)
var v:array[1..100000] of longint;
l, rec:array[1..100000] of longint;
max, pmax, i, j, n:longint;
buf1, buf2:array [1..100000] of char;
f, g:text;
begin
assign (f, 'scmax.in'); settextbuf (f, buf1); reset (f);
assign (g, 'scmax.out'); settextbuf (f, buf2); rewrite (g);
read (f, n); for i := 1 to n do read (f, v[i]);
for i := n-1 downto 1 do
begin
max:=0; pmax:=0;
for j := i+1 to n do
begin
if (v[j]>v[i]) and (l[j]>=max) then
begin
max:=l[j];
pmax:=j;
end;
end;
l[i]:=max+1;
rec[i]:=pmax;
end;
max:=0; pmax:=0;
for i := 1 to n do
begin
if l[i]> max then begin max:= l[i]; pmax:=i; end;
end;
writeln (g, max+1);
while pmax <> 0 do
begin
write (g, v[pmax], ' ');
pmax:=rec[pmax];;
end;
close (f); close (g);
end.