Choose K pancakes from at most 10 to stack largest radius on the bottom, maximizing the exposed surface area divided by pi.
Medium4Brute forceSortingGeometryCombinatoricsInterviewNo attempts yetTime limit5sMemory limit512 MBThe kitchen at the Infinite House of Pancakes has just received an order for a stack of K pancakes. The kitchen has N pancakes available, where N≥K. Every pancake is a cylinder, and different pancakes may have different radii and heights.
As the sous chef, you pick K of the N 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 K 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 K pancakes optimally, what is the largest total exposed surface area you can reach?
The first line contains the number of test cases T. T test cases follow.
The first line of each test case contains two integers N and K, separated by a space. N is the number of pancakes in the kitchen and K is the number of pancakes in the order. Each of the next N lines contains two integers Ri and Hi, the radius and the height of the i-th pancake in millimeters.
Limits
For each test case, print one line in the form Case #x: y, where x is the test case number starting from 1. y is the largest total exposed surface area divided by π.
The exposed surface area is always an integer multiple of π, so y is an integer. Print it as a plain integer, with no decimal point and no exponent. The unit is square millimeters.
In the first sample case the stack holds a single pancake. Using only the first pancake exposes πR02+2πR0H0=14000π mm², and using only the second exposes 44000π mm². The second one is larger, so the answer is 44000.
In the second sample case both pancakes are used. The first contributes its top face and its side, 14000π mm² in total. The second contributes the part of its top face that is not covered plus its side, 34000π mm² in total. The combined area is 48000π mm², so the answer is 48000.
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 14000π mm².
In the fourth sample case the best stack uses the pancakes with radii 8 and 9.