2 Testcase are failing

Ide link

#include
#include
#include
#include

using namespace std;
int main() {
int t;
cin >> t;
while(t–){
int N, no;
int med;
cin >> N;
priority_queue leftheap;
priority_queue<int, vector, greater > rightheap;
cin >> no;
med = no;
cout << med << " ";
leftheap.push(no);
for(int i=1; i<N; i++)
{
cin >> no;
if(leftheap.size() > rightheap.size())
{
if(no < med)
{
rightheap.push(leftheap.top());
leftheap.pop();
leftheap.push(no);
}else{
rightheap.push(no);
}
med = (leftheap.top() + rightheap.top()) / 2;
cout << med << " ";
}else if(leftheap.size() == rightheap.size())
{
if(no > med)
{
rightheap.push(no);
med = rightheap.top();
cout << med << " " ;
}else {
leftheap.push(no);
med = leftheap.top();
cout << med << " ";
}
}else {
if (no > med){
leftheap.push(rightheap.top());
rightheap.pop();
rightheap.push(no);
}else {
leftheap.push(no);
}
med = (leftheap.top() + rightheap.top()) / 2;
cout << med << " ";
}
}
cout << endl;
}
return 0;
}

Your logic is correct, however your code is not optimised.
Check this link to get a better idea of how to implement the same logic.

Can you share the failed testcase Input values? I and confused which one corner case is left.

for n like:9000

test case like this need optimized code