#P13168. [GCJ 2017 #1C] Ample Syrup

    ID: 15035 远端评测题 5000ms 1024MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>2017Special Judge排序Google Code Jam

[GCJ 2017 #1C] Ample Syrup

题目描述

The kitchen at the Infinite House of Pancakes has just received an order for a stack of KK pancakes! The chef currently has NN pancakes available, where NKN \geq K. Each pancake is a cylinder, and different pancakes may have different radii and heights.

As the sous-chef, you must choose KK out of the NN available pancakes, discard the others, and arrange those KK pancakes in a stack on a plate as follows. First, take the pancake that has the largest radius, and lay it on the plate on one of its circular faces. (If multiple pancakes have the same radius, you can use any of them.) Then, take the remaining pancake with the next largest radius and lay it on top of that pancake, and so on, until all KK pancakes are in the stack and the centers of the circular faces are aligned in a line perpendicular to the plate, as illustrated by this example:

You know that there is only one thing your diners love as much as they love pancakes: syrup! It is best to maximize the total amount of exposed pancake surface area in the stack, since more exposed pancake surface area means more places to pour on delicious syrup. Any part of a pancake that is not touching part of another pancake or the plate is considered to be exposed.

If you choose the KK pancakes optimally, what is the largest total exposed pancake surface area you can achieve?

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each begins with one line with two integers NN and KK: the total number of available pancakes, and the size of the stack that the diner has ordered. Then, NN more lines follow. Each contains two integers RiR_i and HiH_i: the radius and height of the ii-th pancake, in millimeters.

输出格式

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the maximum possible total exposed pancake surface area, in millimeters squared. yy will be considered correct if it is within an absolute or relative error of 10610^{-6} of the correct answer.

4
2 1
100 20
200 10
2 2
100 20
200 10
3 2
100 10
100 10
100 10
4 2
9 3
7 1
10 1
8 4
Case #1: 138230.076757951
Case #2: 150796.447372310
Case #3: 43982.297150257
Case #4: 625.176938064

提示

Sample Explanation

In sample case #1, the "stack" consists only of one pancake. A stack of just the first pancake would have an exposed area of $\pi \times R_0^2 + 2 \times \pi \times R_0 \times H_0 = 14000\pi \text{ mm}^2$. A stack of just the second pancake would have an exposed area of 44000π mm244000\pi \text{ mm}^2. So it is better to use the second pancake.

In sample case #2, we can use both of the same pancakes from case #1. The first pancake contributes its top area and its side, for a total of 14000π mm214000\pi \text{ mm}^2. The second pancake contributes some of its top area (the part not covered by the first pancake) and its side, for a total of 34000π mm234000\pi \text{ mm}^2. The combined exposed surface area is 48000π mm248000\pi \text{ mm}^2.

In sample case #3, all of the pancakes have radius 100 and height 10. If we stack two of these together, we effectively have a single new cylinder of radius 100 and height 20. The exposed surface area is 14000π mm214000\pi \text{ mm}^2.

In sample case #4, the optimal stack uses the pancakes with radii of 8 and 9.

Limits

  • 1T1001 \leq T \leq 100.
  • 1KN1 \leq K \leq N.
  • 1Ri1061 \leq R_i \leq 10^6, for all ii.
  • 1Hi1061 \leq H_i \leq 10^6, for all ii.

Small dataset (9 Pts, Test Set 1 - Visible)

  • 1N101 \leq N \leq 10.

Large dataset (16 Pts, Test Set 2 - Hidden)

  • 1N10001 \leq N \leq 1000.