Cod sursa(job #1122416)

Utilizator EuBossuletMuntea Andrei EuBossulet Data 25 februarie 2014 18:03:28
Problema Subsir 2 Scor 45
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.56 kb
Program subsir2;
var a,poz:array[0..5000] of longint;
    i,j,n,max:integer;
    f,q:text;
begin
assign(f,'subsir2.in');
reset(f);
assign(q,'subsir2.out');
rewrite(q);
readln(f,n);
a[0]:=-9000000;
for i:=1 to n do
begin
        read(f,a[i]);
        for j:=i-1 downto 0 do
        if (a[i]>a[j]) and (poz[i]<poz[j]+1) then poz[i]:=poz[j]+1;
        if poz[i]>max then max:=poz[i];
end;
writeln(q,max);
j:=max;
for i:=n downto 1 do if poz[i]=max then begin a[max]:=i; dec(max); end;
for i:=1 to j do write(q,a[i],' ');
close(f);
close(q);
end.