Why TLE in the code

#include<bits/stdc++.h>
using namespace std;

int main()
{
long long int q, k;
cin>> q >> k;

set<long long int> st;

while(q--)
{
     long long int n;
     cin>>n;
     
     if(n == 1)
     {
          long long int x,y;
          cin>> x >> y;
          
          long long int dist = x*x + y*y;
          
          st.insert(dist);
     }
     else if(n == 2)
     {
          auto it = st.begin();
          advance(it, k - 1);
          
          cout<< (*it) << endl; 
     }
}

return 0;

}

hi @devang_11912089
refer this https://ide.codingblocks.com/s/642896

Will you please explain why set giving TLE

hi @devang_11912089
its bcoz in priority queue, we are storing only top k elements, and at top storing our potential ans…

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.