You are given
segments where each segment is of the form .
It is ensured that for any two segments and , one of the following conditions hold true:
- ,
- , or
- (empty set)
Note that denotes the intersection of segments.
In other words, for any two segments, either one is completely inside the other or they are completely disjoint.
The segment is assigned a value .
A subset having segments is considered good if there exists an integer array of size such that:
- All elements of the array are distinct.
- lies in the segment .
Let the score of a good subset be defined as the sum of values of all segments of the subset. Find the maximum score of a good subset.
Input Format
- The first line of input contains a single integer - the number of test cases. The description of test cases follow.
- The first line of each test case contains integers - the number of segments.
- Each of the next lines contains three integers and , describing the segment.
Output Format
For each test case, output the maximum score of a good subset.
Constraints
- Sum of over all test cases does not exceed .
Sample Input 1
2
4
2 2 5
2 2 10
3 3 14
3 3 20
4
1 3 4
2 3 5
1 1 10
1 4 13
Sample Output 1
30
32
Explanation
Test case : A possible value of good subset is . The array such that lies in the segment and lies in the segment . The sum of values of all segments of is .
It can be proven that the score of a good subset does not exceed in this case.
Test case : We can take . The array .
- For segment , and . Here .
- For segment , and . Here .
- For segment , and . Here .
- For segment , and . Here .
The sum of scores of all segments of is . It can be proven that the score of a good subset does not exceed in this case.
No comments:
Post a Comment