Cod sursa(job #252475)

Utilizator FllorynMitu Florin Danut Flloryn Data 4 februarie 2009 14:58:24
Problema Schi Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.29 kb
   var b,sol:array[1..30001] of integer;   a:array[1..120001] of integer;   i,w,n:longint;   f,g:text;  
   procedure umplu(i,st,dr:longint);  
     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.