Please help me to optimize this code
#include <bits/stdc++.h>
using namespace std;
long long int ans(priority_queue b ,int k){
long long int a=0;
while(k>=0){
a=b.top();
b.pop();
k--;
}
return a;
}
void showpq(priority_queue gq)
{
priority_queue <long long int> g = gq;
while (!g.empty())
{
cout << '\t' << g.top();
g.pop();
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int q,k; cin>>q>>k;
priority_queue<long long int> s;
while(q--){
int a;
cin>>a;
if(a==1){
long long int x,y;
cin>>x>>y;
s.push(x*x+y*y);
}
if(a==2){
//showpq(s);
int l=s.size();
int b=ans(s,l-k);
cout<<b<<"\n";
}
}
return 0;
}