Two Yachts
Time limit1sMemory limit256 MB
Pick priced time intervals so no day is covered more than twice and the total price is maximal.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Intervals, Sorting
- Solved
- No attempts yet
Problem
A marine resort put the use of two luxury yachts up for bidding for the coming season. Everyone who takes part in the bidding submits a sealed proposal that gives a period of use and a bidding price. After the bidding closes, the manager of the resort picks proposals so that the periods of use never overlap on a single yacht, and so that the profit is as large as possible. A participant whose proposal is picked uses one yacht for the submitted period. The season consists of days numbered from 1 to .
Because there are two yachts, no day may be covered by three or more of the picked periods.
Suppose there are five proposals.
The manager cannot take all five, because some days are covered by three or more periods. Picking proposals 2 and 5 gives a profit of 130,000. The largest profit comes from proposals 1, 3, and 5, and it is 180,000.
Given proposals, write a program that reports the largest profit the resort can obtain.
Input
Your program reads from standard input. The first line holds the number of test cases .
Each test case begins with the number of proposals (). Each of the next lines holds three integers , , and : the beginning day of the period of use, the ending day of the period of use, and the bidding price (, ).
You may assume that the number of proposals overlapping on the same day is at most 100.
Output
Your program writes to standard output. Print exactly one line for each test case, holding an integer, the largest profit the resort can obtain.