Cod sursă (job #495415)

Utilizator avatar gheorghita.pavel Gheorghita Pavel gheorghita.pavel IP ascuns
Problemă Lalele (clasele 9-10) Compilator cpp | 0,68 kb
Rundă lasm_22_10_cl11_12 Status evaluat
Dată 22 oct. 2019 22:24:34 Scor 40
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

ifstream f("lalele.in");
ofstream g("lalele.out");
 int a[5000001];
int main()
{
    int n,d,x ,z=0,cnt=0,i;
    f>>n;
    while(n>0)
    {
        f>>d>>x;
        n=n-d;
        if(x>0)
        {
        cnt=cnt+d;
        for(i=1; i<=d; ++i)
            {
                ++z;
                a[z]=x+i-1-cnt;
            }
        }
        else
        {
            for(i=1; i<=d; ++i)
            {
                ++cnt;
                nth_element(a+1,a+(z+2)/2,a+z+1);
                g<<a[(z+2)/2]+cnt<<endl;
                z/=2;
        }
    }
    }
    return 0;
}