Pagini recente » Cod sursa (job #1498308) | Cod sursa (job #2648067) | Cod sursa (job #1538623) | Cod sursa (job #594209) | Cod sursa (job #1405523)
program scmax;
type tabel=array[0..100001] of longint;
buf=array[0..1 shl 17] of char;
var t,v,vv:tabel; ff1,ff2:buf;
max,n,i,j:longint;
f1,f2:text;
function maxx(a,b:longint):longint;
begin
if a>b then maxx:=a else maxx:=b;
end;
function cauta(st,dr,x:longint):longint;
var m:longint;
begin
while (st<=dr) do begin
m:=(st+dr) div 2;
if v[m]<x then st:=m+1 else dr:=m-1;
end;
cauta:=st;
end;
begin
assign (f1,'scmax.in');
assign (f2,'scmax.out');
reset (f1);
rewrite (f2);
settextbuf(f1,ff1);
settextbuf(f2,ff2);
readln (f1,n);
for i:=1 to n do read (f1,t[i]);
v[1]:=t[1]; max:=1; vv[1]:=1;
for i:=2 to n do begin
j:=cauta(1,max,t[i]); v[j]:=t[i];
vv[i]:=j; max:=maxx(max,j);
end;
writeln (f2,max); j:=max;
for i:=n downto 1 do
if vv[i]=j then begin v[j]:=t[i]; j:=j-1; end;
for i:=1 to max do write (f2,v[i],' ');
close (f1);
close (f2);
end.