HOSTEL VISIT one test case left

I am not getting this
i try it many times.

with priority queue and deque and but
one test case left.

plz help out this.
here is my code …

#include
#include
#include
#include
using namespace std;
int main(){
int q,k;
deque aux;
priority_queue<int,vector ,greater >pq;
int t,x,y;
cin>>q>>k;

while(q--){
	cin>>t;
	if(t==1){
		cin>>x>>y;
		pq.push(x*x+y*y);
	}
	else if(t==2){

		for(int i = 1 ; i <k ; i++ ){
			aux.push_back(pq.top());
			pq.pop();
			}
            aux.push_back(pq.top());
            cout<<pq.top()<<endl;
            while(!pq.empty()){
                pq.pop();
            }
			while(!aux.empty()){
				pq.push(aux.back());
				aux.pop_back();
			}

	}
}
return 0;

}

We don’t have to pop distances forever.
Please have a look at this very short code.

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.