Cod sursă (job #485993)
Utilizator |
|
IP | ascuns |
---|---|---|---|
Problemă | Lalele (clasele 9-10) | Compilator | cpp | 0,66 kb |
Rundă | Arhiva de probleme | Status | evaluat |
Dată | 13 sept. 2019 14:51:53 | Scor | 100 |
#include <bits/stdc++.h>
using namespace std;
int p[5000002];
ifstream in("lalele.in");
ofstream out("lalele.out");
int main()
{
int i,z=0,n,cnt=0,minn;
in>>n;
while(n>0)
{
int d,x;
in>>d>>x;
n-=d;
if(x)
{
cnt+=d;
for(i=1; i<=d; ++i)
{
++z,p[z]=x+i-1-cnt;
}
}
else
{
for(i=1; i<=d; ++i)
{
++cnt;
nth_element(p+1,p+(z+2)/2,p+z+1);
out<<p[(z+2)/2]+cnt<<'\n';
z/=2;
}
}
}
return 0;
}