Cod sursă (job #495668)

Utilizator avatar mariabd Maria Burdila mariabd IP ascuns
Problemă Lalele (clasele 9-10) Compilator cpp | 1,11 kb
Rundă lasm_22_10_cl11_12 Status evaluat
Dată 22 oct. 2019 23:38:47 Scor 40
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

int n,x,y,s,d,i,a[5000001],b[5000001];

int main(){
	ifstream cin("lalele.in");
    ofstream cout("lalele.out");
    cin>>n;
    
    while ( i<n ){ cin>>x>>y;
                      i+=x;
                  if ( y ){ for ( int j=1;j<=x;++j ){
                                                    a[++s]=y;
                                                    b[s]=++d;
                                                   }
                          }
                      else{  for ( int l=1;l<=s;++l ){
                										a[l]+=d-b[l];
                										b[l]=d;
                                                       }
                            for ( int j=1;j<=x;++j ){ ++d;
                                              nth_element(a+1,a+s/2+1,a+s+1);
                                              s=s/2;
                                              cout<<(a[s+1]+d-b[s+1])<<endl;
                                                 }
                         }
                   }
    return 0;
}