why this gave runtime error
#include<bits/stdc++.h>
using namespace std;
bool cmpr(pair<int,int>l,pair<int,int>r)
{
return l.first>r.first;
}
int main()
{
int t;
cin>>t;
while(t–)
{
int n,i;
cin>>n;
vector<pair<int,int>>v(n);
for(i=0;i<n;i++)
{
cin>>v[i].first>>v[i].second;
}
sort(v.begin(),v.end(),cmpr);
priority_queue<pair<int,int>>pq;
int l,p,count=0,x=0;
cin>>l>>p;
while(l>p && x<n)
{
if(p>=l-v[x].first)
{
pq.push(make_pair(v[x].second,x));
x++;
}
else
{
if(!pq.empty())
{
int t=v[pq.top().second].first;
p=p-(l-t)+pq.top().first;
l=t;
count++;
pq.pop();
}
}
}
if(l>p && pq.empty())
cout<<"-1"<<"\n";
else if(l>p && !pq.empty())
{
while(l>p && !pq.empty())
{
p=p-(l-v[pq.top().second].first)+pq.top().first;
l=v[pq.top().second].first;
count++;
pq.pop();
}
if(l>p)
cout<<"-1"<<"\n";
else
cout<<count<<endl;
}
else
cout<<count<<endl;
}
return 0;
}