Garbage value for 0

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<long long, null_type, less, rb_tree_tag,

int main()
long long q;
cin >> q;
long long k;
cin >> k;
int Q ;
long long x, y;
long long S;
for (int i = 0; i < q; i++)
cin >> Q;
if (Q == 1)
cin >> x >> y;
S = (x * x) + (y * y);
if (Q == 2)
cout << *v.find_by_order(k - 1) << endl;
return 0;

hi @akashagarwal1321
refer this

1 Like

Thank you for putting up the solution but i wish to understand the mistake and the solution of the code which i posted. Please help me to debug .It passed all the cases except one.

hi Akash pls save ur code on ide and send…i will try to figure out the mistake…

1 Like

here is the link -

can u explain ur step wise approach… i am not able to get ur soln…

I have added comments to my code . pls visit the code once more.

@Vaibhav277 are the comments sufficient or i need to explain further if my approach is still not clear?

@Vaibhav277 can u explain the logic behind the code specially pop() part.

logic is that I am storing only the top K elements in my priority queue

1 Like

Ok , i got it and could you figure out the mistake in the code i shared?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.