Mai intai trebuie sa te autentifici.
Cod sursa(job #162843)
Utilizator | Data | 20 martie 2008 19:56:00 | |
---|---|---|---|
Problema | Schi | Scor | 70 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 0.92 kb |
var b,sol:array[1..30000] of integer;
a:array[1..100001] of integer;
i,w,n:longint;
f,g:text;
procedure umplu(i,st,dr:integer);
begin
if (st<=dr) then begin
a[i]:=dr-st+1;
if st<>dr then begin
umplu(i shl 1,st,(st+dr) shr 1);
umplu(i shl 1+1, (st+dr) shr 1+1, dr);
end;
end;
end;
procedure caut(poz,x,st,dr:longint);
begin
if st=dr then begin
a[poz]:=0;
w:=st;
end
else
if a[poz shl 1]< x then begin
dec(a[poz]);
caut(poz shl 1+1,x-a[poz shl 1],(st+dr) shr 1+1, dr);
end
else begin
dec(a[poz]);
caut(poz shl 1, x, st, (st+dr) shr 1);
end;
end;
begin
assign(f,'schi.in'); reset(f);
assign(g,'schi.out'); rewrite(g);
read(f,n);
for i:=1 to n do
read(f,b[i]);
umplu(1,1,n);
for i:=n downto 1 do begin
caut(1,b[i], 1, n);
sol[w]:=i;
end;
for i:=1 to n do
writeln(g,sol[i]);
close(f); close(g);
end.