Cod sursă (job #636370)

Utilizator avatar tomaionut IDorando tomaionut IP ascuns
Problemă Lalele (clasele 9-10) Compilator cpp-32 | 0.82 kb
Rundă Arhiva de probleme Status evaluat
Dată 27 feb. 2022 20:03:44 Scor 80
#include <bits/stdc++.h>

using namespace std;

ifstream fin("lalele.in");
ofstream fout("lalele.out");
int n, x, d, nrzile, h[5000005], zile[5000005];
int main()
{
    int i;
    fin >> x;
    while (fin >> d >> x)
    {
        if (x)
        for (i = 1; i <= d; i++)
        {
            h[++n] = x;
            zile[n] = ++nrzile;
        }
        else
        {
            for (i = 1; i <= n; i++)
            {
                h[i] = h[i] + nrzile - zile[i];
                zile[i] = nrzile;
            }

            for (i = 1; i <= d; i++)
            {
                nrzile++;
                nth_element(h + 1, h + n / 2 + 1, h + n + 1);
                fout << h[n / 2 + 1] + nrzile - zile[n / 2 + 1] << "\n";
                n /= 2;
            }
        }
    }


    return 0;
}