Pagini recente » Cod sursa (job #1863311) | Cod sursa (job #1572903) | Cod sursa (job #662179) | Cod sursa (job #2113961) | Cod sursa (job #314407)
Cod sursa(job #314407)
program p1;
var f,g:text;
a,b,c:array[1..100] of integer;
i,j,n,imax,max:integer;
begin
assign(f,'secv.in');reset(f);
assign(g,'secv.out');rewrite(g);
read(f,n);
for i:=1 to n do read(f,a[i]);
for i:=n downto 1 do
begin
imax:=0;
max:=0;
for j:=i+1 to n do
if a[i]<=a[j] then begin
if max<b[j] then begin
max:=b[j];
imax:=j;
end;
end;
b[i]:=max+1;
c[i]:=imax;
end;
max:=b[1];imax:=1;
for i:=2 to n do
if max<b[i] then begin max:=b[i]; imax:=i; end;
while imax>0 do
begin
write(g,a[imax],' ');
imax:=c[imax];
end;
close(f);
close(g);
end.