#P16591. [GKS 2016 #D] Stretch Rope

    ID: 16564 Type: RemoteJudge 2000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>动态规划 DP2016单调队列背包 DPGoogle Kick Start

[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 NN rubber bands available in the shop. The i-th of these bands can be stretched to have any length in the range [Ai,Bi][A_i, B_i], inclusive. Two rubber bands of range [a,b][a, b] and [c,d][c, d] can be connected to form one rubber band that can have any length in the range [a+c,b+d][a+c, b+d]. 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 LL. This can be either a single rubber band or a combination of rubber bands. You have MM 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, TT. TT test cases follow. Each test case starts with 3 integers NN, MM, LL, the number of rubber bands available in the shop, the number of dollars you have and the desired rubber band length. Then NN lines follow. Each line represents one rubber band and consists of 3 integers, AiA_i, BiB_i, and PiP_i. [Ai,Bi][A_i, B_i] is the inclusive range of lengths that the i-th rubber band can stretch to, and PiP_i is the price of the i-th rubber band in dollars.

输出格式

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 11) and yy 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 [7,9][7, 9], which does not include 66. (Remember, the rubber band must be able to stretch to a length of exactly LL.) The optimal solution is to buy the rubber bands costing 22 and 55 and stick them together; the new band has a stretch range of [4,7][4, 7], which does include 66. You have 88 dollars, so you can afford the total cost of 77 dollars.

In sample case #2, you need to buy all of the rubber bands to be able to stretch to length 1414. That would cost 1212 dollars, but you only have 1111, so this case is IMPOSSIBLE.

Limits

1T1001 \le T \le 100.

1PiM1 \le P_i \le M.

1L100001 \le L \le 10000.

1AiBi100001 \le A_i \le B_i \le 10000.

Small dataset (Test set 1 - Visible)

1N101 \le N \le 10.

1M1001 \le M \le 100.

Large dataset (Test set 2 - Hidden)

1N10001 \le N \le 1000.

1M10000000001 \le M \le 1000000000.