Pagini recente » Cod sursa (job #168575) | Cod sursa (job #1139997) | Cod sursa (job #2561431) | Cod sursa (job #1865714) | Cod sursa (job #574976)
Cod sursa(job #574976)
var best,a,poz:array[1..100000] of longint;
max,sol,p,n,i,j:longint;
s:string;
f1,f2:text;
begin
assign(f1,'scmax.in');
assign(f2,'scmax.out');
reset(f1);
rewrite(f2);
readln(f1,n);
{ for i:=1 to n do
read(f1,a[i]);}
i:=1;
while not eoln(f1) do
begin
read(f1,s);
for j:=1 to length(s) do
if s[j]=' ' then inc(i) else a[i]:=a[i]*10+ord(s[j])-ord('0');
end;
best[n]:=1;
poz[n]:=-1;
max:=1;
p:=n;
for i:=n-1 downto 1 do
begin
best[i]:=1;
poz[i]:=-1;
for j:=i+1 to n do
if (a[i]<a[j])and(best[i]<best[j]+1) then
begin
best[i]:=best[j]+1;
poz[i]:=j;
if best[i]>max then begin max:=best[i]; p:=i; end;
end;
end;
writeln(f2,max);
i:=p;
while i>0 do
begin
write(f2,a[i],' ');
i:=poz[i];
end;
close(f2);
end.