Cod sursă (job #485805)

Utilizator avatar edyman Sandu Eduard edyman IP ascuns
Problemă Lalele (clasele 9-10) Compilator cpp | 1,75 kb
Rundă Arhiva de probleme Status evaluat
Dată 12 sept. 2019 19:55:20 Scor 0
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lalele.in");
ofstream fout("lalele.out");
int v[5000000];
int x[3000000];
int m[5000000];
int main()
{
    int i,j,n,k,xx,d,poz = 0,z = 0,nr,pozd = 0,pozx = 0,f = 1,cz,c,cd,con,ramas,cnt;
    fin>>nr;
    while(fin>>d>>xx)
    {
        if(xx)
        {
            pozd++;
            pozx++;
            v[pozd] = d;
            x[pozx] = xx;
            poz += d;
            z++;
        }
        else
        {
            poz += d;
            f=1;
            cz = z;
            con = 1;
            while(con<=z)
            {
                while(v[con])
                {
                    m[f] = x[con] + poz - 1;
                    v[con]--;
                    f++;
                    poz--;
                }
                con++;
            }
            sort(m+1,m+f);
            c = f-1;
            cd = d;
            while(d)
            {
                ramas = c - (c - (c/2 + 1) + 1);
                c = c/2 + 1;
                fout<<m[c]-d+1<<'\n';
                d--;
            }
            i = 1;
            ramas--;
            pozx = 1;
            pozd = 1;
            v[i] = 1;
            x[i] = m[1];
            i = 2;
            cnt = 1;
            poz = 1;
            z = 1;
            while(ramas)
            {
                if(m[i] == m[i-1]+1)
                {
                    v[cnt]++;
                }
                else{
                    z++;
                    cnt++;
                    v[cnt] = 1;
                    x[cnt] = m[i];
            }
            poz ++;
            i++;
            ramas--;
            }
            f = 1;
        }
    }
    return 0;
}