Pagini recente » Cod sursa (job #1851950) | Cod sursa (job #1004623) | Cod sursa (job #2990606) | Cod sursa (job #517342) | Cod sursa (job #65104)
Cod sursa(job #65104)
var a,b:array[1..5000] of longint;
n,i,j,k,l:longint;
begin
assign(input,'subsir2.in');
assign(output,'subsir2.out');
reset(input);
reset(output);
readln(n);
for i:=1 to n do read(a[i]);
for i:=n-1 downto 1 do
begin
max:=0;
for j:=i+1 to n do
if (a[i]<a[j])and(max<b[j]) then max:=b[j];
end;
max:=0;
for i:=1 to n do
if b[i]>max then max:=b[i];
writeln(max);
poz:=1;
repeat
min:=maxlongint;
for i:=poz to n do
if (b[i]=max)and(a[i]<min) then
poz:=i;
write(a[i],' ');
dec(max);
until max=0;
close(input);
close(output);
end.