Error in hostel visit question

this is my code,what is wrong with it

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int t;cin>>t;
int k;cin>>k;
priority_queue pq;
while(t–)
{
ll q;cin>>q;
if(q==1)
{
ll x,y;
cin>>x>>y;
ll distance=(xx)+(yy);

        if(pq.size()<k)
            pq.push(distance);
        else
        {
            pq.pop();
            pq.push(distance);
        }
    }
    else 
     cout<<pq.top()<<endl;

}

return 0;

}

You need to make a check before removing the element and inserting a new one in the priority queue.
See https://ide.codingblocks.com/s/572661

1 Like

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.