Cod sursă (job #94848)

Utilizator avatar nita_teddy Teddy Nita nita_teddy IP ascuns
Problemă Lalele (clasele 9-10) Compilator cpp | 0,79 kb
Rundă Tema 9 clasele 9-10 2014/15 Status evaluat
Dată 4 dec. 2014 17:02:04 Scor 85
#include <cstdio>
#include <algorithm>

using namespace std;

FILE*f=fopen("lalele.in","r");
FILE*h=fopen("lalele.out","w");

int n,x,y,top,zi,i,v[5000001],k[5000001];

int main(){
    fscanf(f,"%d",&n);
    while ( i<n ){
        fscanf(f,"%d%d",&x,&y);
        i+=x;
        if ( y!=0 ){
            for ( int j=1;j<=x;++j ){
                v[++top]=y;
                k[top]=++zi;
            }
        }
        else{
            for ( int j=1;j<=x;++j ){
                ++zi;
                for ( int l=1;l<=top;++l ){
                    v[l]+=zi-k[l];
                    k[l]=zi;
                }
                nth_element(v+1,v+top/2+1,v+top+1);
                top=top/2;
                fprintf(h,"%d\n",v[top+1]);
            }
        }
    }
    return 0;
}