Pagini recente » Cod sursa (job #1298612) | Cod sursa (job #39487) | Cod sursa (job #1114941) | Cod sursa (job #1055490) | Cod sursa (job #5420)
Cod sursa(job #5420)
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.