Pagini recente » Cod sursa (job #66587) | Cod sursa (job #398036) | Cod sursa (job #1063382) | Cod sursa (job #2574981) | Cod sursa (job #1052707)
program scmax;
var a,sol,drum:array[1..100000] of longint;
n,i,j,max,h:longint;
procedure scrie(h:longint);
begin
if h>0 then begin
scrie(drum[h]);
write(a[h],' ');
end;
end;
begin
assign(input,'scmax.in');
reset(input);
assign(output,'scmax.out');
rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
sol[1]:=1;
for i:=2 to n do begin
max:=0; drum[i]:=0;
for j:=1 to i do
if (a[i]>a[j]) and (sol[j]>max) then begin
max:=sol[j];
drum[i]:=j;
end;
sol[i]:=max+1;
end;
max:=sol[1]; h:=1;
for i:=1 to n do if sol[i]>max then begin max:=sol[i]; h:=i; end;
writeln(max);
scrie(h);
{while h <>0 do begin
write(a[h], ' ');
h:=drum[h];
end; }
close(output);
end.