Sure here goes the updated code
#include
#include
#include
using namespace std;
#define ll long long int
bool sortinrev(const pair<ll,ll> &a,
const pair<ll,ll> &b)
{
return (a.first > b.first);
}
int main()
{
ll t;
cin>>t;
while(t–)
{
ll n;
cin>>n;
vector <pair<ll,ll>> x;
for(ll i=1;i<=n;i++)
{
ll a,b;
cin>>a>>b;
x.push_back(make_pair(a,b));
}
ll D,cf;
cin>>D>>cf;
ll nxtd=0,minno=0,flag=0,pre=0;
sort(x.begin(),x.end(),sortinrev);
for(auto i:x)
{
nxtd=D-i.first-pre;
pre=D-i.first;
cf=cf-nxtd+i.second;
minno++;
if(cf>=i.first)
{
flag=1;
break;
}
}
if(flag==1)
cout<<minno<<endl;
else
cout<<-1<<endl;
}
}