不知道为什么一是WA。
#include <iostream>
#include <cstdlib>
const int MAX = 10000 + 10;
using namespace std;
typedef struct
{
int a;
int b;
int c;
}node;
int compare(const void* node0, const void* node1)
{
return ((node*)node0)->b - ((node*)node1)->b;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int N;
node A[MAX];
cin>>N;
for(int i = 0; i < N; i++)
{
int a, b, c;
cin>>a>>b>>c;
A[i].a = a;
A[i].b = b;
A[i].c = c;
}
qsort(A, N, sizeof(node), compare);
int max = 0;
for(int i = 0; i < N; i++)
{
int m = A[i].a;
for(int j = i+1; j < N; j++)
{
if(A[j].b>=A[i].b+A[i].c)break;//当第j个入住时间大于等于第i个离开时间时就跳出循环
m += A[j].a;
}
if(m>max)max = m;
}
cout<<max<<endl;
}
return 0;
}