Cod sursă (job #699611)

Utilizator avatar alexandraprodan51 prodan alexandra alexandraprodan51 IP ascuns
Problemă Lalele (clasele 9-10) Compilator cpp-32 | 0,78 kb
Rundă Arhiva de probleme Status evaluat
Dată 27 feb. 2023 20:35:11 Scor 0
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("lalele.in");
ofstream fout("lalele.out");
int i,n,j,k,d,x,v[1001],l;
int main()
{
    fin>>n;
    i=1;
    while(i<=n)
    {
        fin>>d>>x;
        i+=d;
        if(x>0)
        {
            for(j=1; j<=k; j++) v[j]+=d;
            for(j=1; j<=d; j++)
            {
                k++;
                v[k]=x+j;
            }
        }
        else
        {
            sort(v+1,v+k+1);
            for(j=1; j<=d; j++)
            {
                fout<<v[k/2+1]<<'\n';
                for(l=1; l<=k/2; l++) v[l]++;
                k=k/2+1;
            }
        }
        //for(l=1; l<=k; l++) fout<<v[l]<<" ";
        //fout<<'\n';
    }
    return 0;
}