Please help the answer seems to come out fine but it shows tle

#include<bits/stdc++.h>
using namespace std;
int distance(int x)
{
return xx2;
}
int popmethod(priority_queue<int,vector,greater >pq,int k)
{
k–;
while(k–)
{
pq.pop();
}
int ans=pq.top();
return ans;
}

int main()
{
int n,k;
priority_queue<int,vector,greater >pq;
cin>>n>>k;
while(n–)
{
int a=k;
int q;
cin>>q;
if(q==1)
{
int x,y;
cin>>x>>y;
int dis=distance(x);
pq.push(dis);
}
else{
cout<<popmethod(pq,k)<<endl;
}

}
}

hello @Kshitij-Taneja-2315806971864318
you are getting tle becuase u are using min heap.
for each query of type two u will pop k elements so in worst case for q such query u will be performing q*k operations which will give tle.

use max heap to answer this query efficiently.