Pagini recente »
Profil carla-morie
|
Monitorul de evaluare
|
Rating Foros Valentin (valentin2612)
|
Monitorul de evaluare
|
Cod sursă (job #486234)
Cod sursă (job
#486234)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("lalele.in");
ofstream out("lalele.out");
struct ura
{
int h,zi;
};
bool comp(ura x,ura y)
{
if(x.h<y.h)
return true;
else
return false;
}
ura v[5000001];
int main()
{
int n,d,x,q=0,i,l,j;
in>>n;
for(i=1;i<=n;)
{
in>>d>>x;
if(x!=0)
for(j=1;j<=d;j++,i++)
{
v[++q].h=x;
v[q].zi=i;
}
else
{
int k=q/2;
for(l=1;l<=q;l++)
{
v[l].h+=(i-v[l].zi);
}
for(j=1;j<=d;j++)
{
nth_element(v+1,v+q/2+1,v+q+1,comp);
out<<v[q/2+1].h<<'\n';
q=q/2;
++i;
for(l=1;l<=q;l++)
v[l].h+=1;
}
}
}
return 0;
}