2nd test case fails in Hostel Visit

#include<bits/stdc++.h>
using namespace std;
int main()
{
long int k,q;
cin>>q>>k;
vector x;
while(q–)
{
int n;
cin>>n;
if(n==1)
{
long int z,y;
cin>>z>>y;
long long int r=zz+yy;
x.push_back®;
}
else if(n==2)
{
sort(x.begin(),x.end());
cout<<x[k-1]<<endl;
}

 }

}

why there is TLE in 2nd test case?

See the constraints, Queries are very large. You can’t just sort a vector every time.
Think of it using priority_queue.

Why can we not just sort vector every time

Maximum queries can be of the order 10^5
Sorting takes Nlogn time
If you keep on sorting every time, it may take upto N(Nlogn) time which would cause TLE.

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.