RENT - Rent your airplane and make money


"ABEAS Corp." is a very small company that owns a single airplane. The customers of ABEAS Corp are large airline companies which rent the airplane to accommodate occasional overcapacity.

Customers send renting orders that consist of a time interval and a price that the customer is ready to pay for renting the airplane during the given time period. Orders of all the customers are known in advance. Of course, not all orders can be accommodated and some orders have to be declined. Eugene LAWLER, the Chief Scientific Officer of ABEAS Corp would like to maximize the profit of the company.

You are requested to compute an optimal solution.

Small Example

Consider for instance the case where the company has 4 orders:

  • Order 1 (start time 0, duration 5, price 10)
  • Order 2 (start time 3, duration 7, price 8)
  • Order 3 (start time 5, duration 9, price 7)
  • Order 4 (start time 6, duration 9, price 8)

The optimal solution consists in declining Order 2 and 3 and the gain is 10+8 = 18.
Note that the solution made of Order 1 and 3 is feasible (the airplane is rented with no interruption from time 0 to time 14) but non-optimal.

Input

The first line of the input contains a number T ≤ 30 that indicates the number of test cases to follow. The first line of each test case contains the number of orders n (n ≤ 10000). In the following n lines the orders are given. Each order is described by 3 integer values: The start time of the order st (0 ≤ st < 1000000), the duration d of the order (0 < d < 1000000), and the price p (0 < p < 100000) the customer is ready to pay for this order.

Output

You are required to compute an optimal solution. For each test case your program has to write the total price paid by the airlines.

Example

Input:
1
4
0 5 10
3 7 14
5 9 7
6 9 8

Output:
18
Warning: large Input/Output data, be careful with certain languages

hide comments
macbox: 2016-07-04 09:35:42

For those who think that the judge is giving wrong result.
Read the question again. The second column refers to duration and not the end time.
Correct it and your solution will get accepted.

siddharth: 2016-07-02 12:15:02

I feel something is wrong with the test cases. I am sure my solution is right, still it is giving me WA. I have used weighted Job Scheduling. Admin @Adrian Kuegel can you please confirm as many have pointed out that the test cases are weak.

surayans tiwari(http://bit.ly/1EPzcpv): 2016-06-20 07:59:08

easy dp, linear search also works

MD. Shakhawat hossain sajal: 2016-06-10 11:19:04

why need binary search ???
it's a straightforward classical DP..

hash7: 2016-05-19 21:08:33

alternate way::::: use weighted job scheduling . and if using vector do not forget to clear it .... costed me 3 wa -_-

Last edit: 2016-05-19 21:09:45
yuvan: 2016-03-31 19:26:38

is the output for your example is 42 or 43

naruto09: 2016-02-13 06:59:05

my first dp+binarysearch..^_^

try2catch: 2016-01-30 08:35:56

huh! 4 hr... AC in 1st
these type of problem always confuses me ^_-

sbansalcs: 2015-10-14 19:44:47

Is everything fine with the testcases? Getting WA . Pretty sure that the solution is correct.
Using LIS.

Apoorv Dwivedi: 2015-08-30 09:27:15

no need for binary search linear search also works (very weak test cases).


Added by:Adrian Kuegel
Date:2004-07-13
Time limit:3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:ACM Southwestern European Regional Contest, Paris 2003