Ample Syrup (Small)
InterviewTime limit5sMemory limit512 MB
Choose K pancakes from at most 10 to stack largest radius on the bottom, maximizing the exposed surface area divided by pi.
- Level
Medium4 of 10
- Topics
- Brute force, Sorting, Geometry, Combinatorics
- Solved
- No attempts yet
Problem
The kitchen at the Infinite House of Pancakes has just received an order for a stack of pancakes. The kitchen has pancakes available, where . Every pancake is a cylinder, and different pancakes may have different radii and heights.
As the sous chef, you pick of the pancakes, discard the rest, and stack the chosen ones like this. First, take the pancake with the largest radius and lay it on the plate on one of its circular faces. If several pancakes share that radius, you can use any of them. Then take the remaining pancake with the next largest radius, lay it on top, and continue until all pancakes are stacked. The centers of the circular faces all sit on one line perpendicular to the plate, as in the picture below.

There is one thing your diners love as much as pancakes: syrup. More exposed pancake surface means more room for syrup, so you want the total exposed surface area to be as large as possible. Any part of a pancake that touches neither another pancake nor the plate counts as exposed.
If you pick the pancakes optimally, what is the largest total exposed surface area you can reach?
Input
The first line contains the number of test cases . test cases follow.
The first line of each test case contains two integers and , separated by a space. is the number of pancakes in the kitchen and is the number of pancakes in the order. Each of the next lines contains two integers and , the radius and the height of the -th pancake in millimeters.
Limits
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting from 1. is the largest total exposed surface area divided by .
The exposed surface area is always an integer multiple of , so is an integer. Print it as a plain integer, with no decimal point and no exponent. The unit is square millimeters.
Notes
In the first sample case the stack holds a single pancake. Using only the first pancake exposes mm², and using only the second exposes mm². The second one is larger, so the answer is .
In the second sample case both pancakes are used. The first contributes its top face and its side, mm² in total. The second contributes the part of its top face that is not covered plus its side, mm² in total. The combined area is mm², so the answer is .
In the third sample case every pancake has radius 100 and height 10. Stacking two of them gives the same shape as one cylinder of radius 100 and height 20, whose exposed area is mm².
In the fourth sample case the best stack uses the pancakes with radii 8 and 9.