Street Tree Props (Small)
Time limit5sMemory limit512 MB
Each of up to 10 trees needs one stick of strength B or two sticks summing to B, using the smallest total strength.
- Level
Medium6 of 10
- Topics
- Backtracking, Sorting
- Solved
- No attempts yet
Problem
You were elected mayor of city G. As part of a beautification project you decided to plant street trees along the road, and only after buying the trees did you learn that a tree needs a prop to grow properly.
You want to know whether the wooden sticks you already own are enough to prop up every tree you bought. The conditions are below.
- Every tree must be supported.
- You know the support each tree needs and the support each stick provides. Every tree needs the same support .
- A tree is propped up with wooden sticks. If only one stick is used, its support must be at least .
- Sticks with the same support are grouped into one type, and the count of each type is known. One stick can be used for at most one tree.
- This is a beautification project, so a tree may use at most 2 props. When two sticks are used, they hold the tree with the sum of their supports.
Among all ways that satisfy the conditions above, minimize the total support of the sticks you use.
Input
Define the variables as follows.
- = the number of test cases
- = the number of trees
- = the support one tree needs (the same for every tree)
- = the number of stick types
- = the support provided by a stick of the -th type
- = the number of sticks of the -th type
The first line holds , and test cases follow. Each test case has this format.
N M B
p1 q1
p2 q2
...
pM qM
Limits
- Every input value is an integer.
Output
For each test case print one line of the form Case #x: y, where is the test case number starting from 1. If every street tree can be propped up, print in place of the minimum total support of the sticks used. Otherwise print -1 in place of .