贪心法,过了10/13
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define x first
#define y second
typedef pair<int, pair<int,int>> PIII;
const int N = 1e5+10;
PIII a[N];
int T,n;
void solve()
{
cin>>n;
for (int i = 0; i < n; i ++ )
{
int t,d,l;
cin>>t>>d>>l;
a[i] = {t+d,{t,l}};
}
sort(a,a+n);
int res = 0;
for (int i = 0; i < n-1; i ++ )
{
res = max(res,a[i].y.x);
if(res + a[i].y.y > a[i+1].x)
{
cout<<"NO"<<endl;
return;
}
res += a[i].y.y;
}
cout<<"YES"<<endl;
}
int main()
{
cin>>T;
while(T--)
{
solve();
}
return 0;
}
后续补正解