Candy Store (Small)
Time limit5sMemory limit512 MB
Pick the fewest integer-weight boxes so up to k visitors, each asking 1 to C grams in unknown order, each receive an exact subset of the remaining boxes.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Running a candy store means optimizing one thing after another. The best seller right now is a candy called Whizboppers. Whizboppers go rotten very quickly, which forces two rules on you.
- You must buy new Whizboppers from your supplier every morning.
- You must sell Whizboppers only out of the boxes you bought that morning.
You can order a box of any weight from your supplier, as long as the weight is an integer number of grams. A box cannot be split, so a customer always receives whole boxes.
Up to people visit your store each day. Starting from the first person, each one picks an integer amount to spend on Whizboppers, between and cents inclusive. Whizboppers cost cent per gram, so a person who wants to spend cents must receive exactly grams. You may hand over one 4-gram box, or one 2-gram box and two 1-gram boxes.
Whatever amounts the people pick, you have to give every one of them the exact mass they paid for. Find the minimum number of boxes you need to order in the morning.
Note: when a person picks an amount, you know what the earlier people bought, but you do not know what the later people will buy.
For example, take and . Four 1-gram boxes are enough, but two 1-gram boxes and one 2-gram box, three boxes in total, also work.
- If the first person spends cents, give the 2-gram box. The two remaining 1-gram boxes cover both cent and cents for the second person.
- If the first person spends cent, give one 1-gram box. The remaining 1-gram box and 2-gram box cover both cent and cents for the second person.
Whatever the first person picks, the second person still gets an exact mass, so the answer for , is .
Input
The first line contains the number of test cases . Each of the next lines contains two integers and : the largest number of people that may visit in one day, and the largest amount one person may spend.
Limits
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting from and is the minimum number of boxes you need to order every morning.
Hint
In the first case, one 1-gram box and one 2-gram box cover , and cents. In the second case, buy two 1-gram boxes and one 2-gram box. In the fourth case, two 1-gram boxes, one 2-gram box and one 3-gram box handle both people.