i created a max heap and kept its size strictly below k.
#include
#include
#include
#include
#include
using namespace std;
class Hostel
{
public:
int x,y;
int ans()
{
return x*x +y*y;
}
};
int main(int argc, char const *argv[])
{
int q,k;
cin>>q>>k;
priority_queue <int> map;
while(q--)
{
int why;
cin>>why;
if(why==1)
{
int x,y;
cin>>x>>y;
map.push(x*x+y*y);
if(map.size()>k)
{
map.pop();
}
}
else
{
cout<<map.top()<<endl;
}
}
return 0;
}