Cod sursa(job #5420)

Utilizator vanila0406Ionescu Victor vanila0406 Data 12 ianuarie 2007 13:53:22
Problema Subsir 2 Scor 14
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.42 kb
program subsir2;
var fi,g:text;
        n:longint;
        v:array[1..5001] of longint;
        b:array[1..5001] of byte;
        max:longint;



procedure iofile;
var i,j:longint;
begin
        assign(fi,'subsir2.in');
        reset(fi);
        assign(g,'subsir2.out');
        rewrite(g);
        readln(fi,n);
        max:=-1;
        for i:=1 to n do
                read(fi,v[i]);
        close(fi);
        for i:=n downto 1 do
                begin
                        b[i]:=1;
                        for j:=i+1 to n do
                                if v[i]<v[j] then
                                        if b[i]<b[j]+1 then
                                        b[i]:=b[j]+1;
                        if b[i]>max then max:=b[i];
                end;
end;




procedure prel;
var poz,vl,i,min:longint;
begin
        poz:=0;
        vl:=max;
        repeat
                min:=maxlongint;
                for i:=poz+1 to n do
                        if b[i]=vl then
                                if v[i]<min then
                                        begin
                                                min:=v[i];
                                                poz:=i;
                                        end;
                write(g,poz,' ');
                dec(vl);
        until vl=0;
        close(g);
end;





begin
        iofile;
        prel;
end.