sir it gives me wrong answer why https://ide.codingblocks.com/s/262384
the output is correct
Median in a stream of running integers
sir i updated my code now it works for all testcase but still two test case give tle why
you have applied conditions in wrong way
first you have to compare both the heaps and then check x with median
correct way to do it
if (s.size() > g.size())
{
if (x < med)
{
g.push(s.top());
s.pop();
s.push(x);
}
else
g.push(x);
med = (s.top() + g.top())/2;
}
// case2(both heaps are balanced)
else if (s.size()==g.size())
{
if (x < med)
{
s.push(x);
med = (double)s.top();
}
else
{
g.push(x);
med = (double)g.top();
}
}
// case3(right side heap has more elements)
else
{
if (x > med)
{
s.push(g.top());
g.pop();
g.push(x);
}
else
s.push(x);
med = (s.top() + g.top())/2.0;
}
cout << med << endl;
s is max heap g is min heap
okay let me check again
you have done same mistake try to use approach discuss above
sir please reply why it gives me still tle
no it will not give tle
have you use the approach i provide you
send me the link of code which is giving tle