#P16591. [GKS 2016 #D] Stretch Rope
[GKS 2016 #D] Stretch Rope
题目描述
Mary likes playing with rubber bands. It's her birthday today, and you have gone to the rubber band shop to buy her a gift.
There are rubber bands available in the shop. The i-th of these bands can be stretched to have any length in the range , inclusive. Two rubber bands of range and can be connected to form one rubber band that can have any length in the range . These new rubber bands can themselves be connected to other rubber bands, and so on.
You want to give Mary a rubber band that can be stretched to a length of exactly . This can be either a single rubber band or a combination of rubber bands. You have dollars available. What is the smallest amount you can spend? If it is impossible to accomplish your goal, output IMPOSSIBLE instead.
输入格式
The first line of the input gives the number of test cases, . test cases follow. Each test case starts with 3 integers , , , the number of rubber bands available in the shop, the number of dollars you have and the desired rubber band length. Then lines follow. Each line represents one rubber band and consists of 3 integers, , , and . is the inclusive range of lengths that the i-th rubber band can stretch to, and is the price of the i-th rubber band in dollars.
输出格式
For each test case, output one line containing Case #x: y, where is the test case number (starting from ) and is IMPOSSIBLE if you cannot buy rubber bands to satisfy the goal described above, or otherwise an integer: the minimum price you can pay.
2
3 8 6
3 5 2
4 4 3
1 2 5
3 11 14
1 3 4
5 5 3
2 6 5
Case #1: 7
Case #2: IMPOSSIBLE
提示
In sample case #1, none of the rubber bands in the shop are long enough on their own. It will not work to buy the two cheapest rubber bands and stick them together, because the new band would have a stretch range of , which does not include . (Remember, the rubber band must be able to stretch to a length of exactly .) The optimal solution is to buy the rubber bands costing and and stick them together; the new band has a stretch range of , which does include . You have dollars, so you can afford the total cost of dollars.
In sample case #2, you need to buy all of the rubber bands to be able to stretch to length . That would cost dollars, but you only have , so this case is IMPOSSIBLE.
Limits
.
.
.
.
Small dataset (Test set 1 - Visible)
.
.
Large dataset (Test set 2 - Hidden)
.
.