Cod sursa(job #636809)
Utilizator | Cont vechi Buzu_Tudor_Ro | Data | 19 noiembrie 2011 23:57:06 |
---|---|---|---|
Problema | Subsir crescator maximal | Scor | 10 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.98 kb |
Program arena_crescator;
var fi,fo : text;
a,b,c : array[1..100005] of longint;
i,j,n,max,j1 : longint;
begin
assign(fi,'scmax.in'); reset(fi); readln(fi,n);
assign(fo,'scmax.out'); rewrite(fo);
for i:=1 to n do read(fi,a[i]);
b[n]:=1; max:=0;
for i:=n-1 downto 1 do begin
b[i]:=1;
for j:=i+1 to n do if (a[i]<a[j]) and (b[i]<b[j]+1) then begin
b[i]:=b[j]+1;
max:=b[i];
c[max]:=a[i];
end;
end;
writeln(fo,max);
j:=n;
while c[2]>a[j] do j:=j-1;
c[1]:=a[j];
for i:=max downto 1 do write(fo,c[i],' ');
close(fi); close(fo);
end.