December Circuits '20 Customer satisfaction problem

Someone plz help me with the problem Customer satisfaction of December Circuits '20 on hackerearth

My code is here but i can’t find what is wrong it is showing WA in 10/13 test cases

bool check(vector<pair<ll,ll>>&a,ll n,ll val)
{
    ll total=0;
    for(int i=1;i<n;i++)
    {
        total+=val*(a[i].first-a[i-1].first);
       // cout<<"total="<<total<<" w"<<a[i].second<<endl;
        if(total<a[i].second)
        {
     //       cout<<"returning false"<<endl;
            return false;
        }
        else
        {
            total-=a[i].second;
        }
        
    }
   // cout<<"returning true"<<endl;
    return true;
}
void solve()
{
    ll n;
    cin>>n;
    vector<pair<ll,ll>>a;
    a.push_back({0,0});
    while(n--)
    {
        ll l,r,w;
        cin>>l>>r>>w;
        a.push_back({r,w});
    }
    sort(all(a));
    ll l=0;
    ll r=1e18;
    ll ans;
    n=a.size();
    while(r>=l)
    {
        ll mid=(r+l)/2;
        ans=mid;
        bool d=check(a,n,mid);
        if(d==true)
        {
            r=mid-1;
        }
        else
        {
            l=mid+1;
        }
        
    }
    //cout<<r<<l<<endl;
    cout<<l<<endl;
}



int main()
{
    Fast
    ll t=1;
/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
*/
    cin>>t;
    for(ll i=1;i<=t;i++)
    {
      solve();
    }

    
    return 0;
}