Sort the start time first, and leave the queue earlier than the end time using the priority queue;
Because the time is only 20000, We can enumerate each unit of time to see the task to be assigned,
If an end time in a queue is longer than the enumerated time, the result is displayed on the right of the MID.
# Include <stdio. h>
# Include <iostream>
# Include <string. h>
# Include <algorithm>
# Include <stdlib. h>
# Include <math. h>
# Include <queue>
Using namespace STD;
Int t, n;
Struct Node
{
Double R, D, W;
Bool operator <(const node & TT) const {
Return D> TT. D;
}
} Work [1, 10005];
// Bool CMP (node A, Node B)
//{
// Return a. r <B, R;
//}
Bool CMP (node A, Node B ){
Return a. r <B. R;
}
Void Init ()
{
Scanf ("% d", & N );
For (INT I = 0; I <n; I ++)
Scanf ("% lf", & work [I]. R, & work [I]. D, & work [I]. W );
Sort (work, work + N, CMP );
}
Int judge (INT mid)
{
Priority_queue <node> q;
Int wn = 0;
For (INT I = 1; I <= 20000; I ++)
{
Int sum = mid;
While (work [wn]. r <I & wn! = N) // the start time is less than I & the task is not fully determined, and the team enters the queue
Q. Push (work [wn ++]);
While (sum! = 0 &&! Q. Empty ())
{
Node save = Q. Top (); q. Pop ();
If (I> Save. d) return false;
If (save. W> sum) // The task time is greater than the given rate.
{
Save. W-= sum;
Sum = 0;
Q. Push (SAVE );
}
Else
Sum-= save. W;
}
If (wn = N & Q. Empty () break;
}
If (wn = N & Q. Empty ())
Return true;
Return false;
}
Int solve ()
{
Int L = 0, r = 10000000, mid;
While (L <R)
{
If (R-l = 1) break;
Mid = (L + r)> 1;
If (! Judge (MID) L = mid;
Else
R = mid;
}
Return R;
}
Int main ()
{
Scanf ("% d", & T );
While (t --)
{
Init ();
Printf ("% d \ n", solve ());
}
Return 0;
}