Cod sursa(job #1074498)

Utilizator gegeadDragos Gegea gegead Data 7 ianuarie 2014 18:23:42
Problema Schi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include<fstream>
#include<cstdio>
#define inf 1000000001
using namespace std;
int t[100001],v[30001],a[30001];

ifstream in("schi.in");



int main()
{
    freopen("schi.out","w",stdout);
    int i,pozx,pozy,val,n,m;
    in>>n;
    for(i=1;i<=n;++i)
        in>>v[i];
    for(i=n;i>=1;--i)
    {
        pozx=1;
        pozy=n;
        val=1;
        ++t[val];
        while(pozx!=pozy)
        {
            m=(pozx+pozy)/2;
            if(m-pozx+1-t[val*2]>=v[i])
            {
                pozy=m;
                val*=2;
                ++t[val];
            }
            else
            {
                v[i]=v[i]-(m-pozx+1-t[val*2]);
                pozx=m+1;
                val=val*2+1;
                ++t[val];
            }
        }
        a[pozy]=i;
    }
    for(i=1;i<=n;++i)
        printf("%d\n",a[i]);
    return 0;
}