#P13369. [GCJ 2011 #1B] Revenge of the Hot Dogs

    ID: 15236 远端评测题 3000~6000ms 1024MiB 尝试: 0 已通过: 0 难度: 4 上传者: 标签>数学贪心2011二分Special JudgeGoogle Code Jam

[GCJ 2011 #1B] Revenge of the Hot Dogs

题目描述

Last year, several hot dog vendors were lined up along a street, and they had a tricky algorithm to spread themselves out. Unfortunately, the algorithm was very slow and they are still going. All is not lost though! The hot dog vendors have a plan: time to try a new algorithm!

The problem is that multiple vendors might be selling too close to each other, and then they will take each other's business. The vendors can move along the street at 1 meter/second. To avoid interfering with each other, they want to stand so that every pair of them is separated by a distance of at least DD meters.

Remember that the street is really long, so there is no danger of running out of space to move in either direction. Given the starting positions of all hot dog vendors, you should find the minimum time they need before all the vendors are separated (each two vendors are at least DD meters apart from each other).

输入格式

Each point of the street is labeled with a number, positive, negative or zero. A point labeled pp is p|p| meters east of the point labeled 00 if pp is positive, and p|p| meters west of the point labeled 00 if pp is negative. We will use this labeling system to describe the positions of the vendors in the input file.

The first line of the input file contains the number of cases, TT. TT test cases follow. Each case begins with a line containing the number of points CC that have at least one hot dog vendor in the starting configuration and an integer DD -- the minimum distance they want to spread out to. The next CC lines each contain a pair of space-separated integers PP, VV, indicating that there are VV vendors at the point labeled PP.

输出格式

For each test case, output one line containing "Case #xx: yy", where xx is the case number (starting from 1) and yy is the minimum amount of time it will take for the vendors to spread out apart on the street. Answers with relative or absolute error of at most 10610^{-6} will be accepted.

2
3 2
0 1
3 2
6 1
2 2
0 3
1 1

提示

Limits

  • 1T501 \leq T \leq 50.
  • All the values PP are integers in the range [105,105][-10^5, 10^5].
  • Within each test case all PP values are distinct and given in an increasing order. The limit on the sum of VV values is listed below. All the VV values are positive integers.

Small dataset (15 Pts, Test set 1 - Visible)

  • 1D51 \leq D \leq 5
  • 1C201 \leq C \leq 20.
  • The sum of all the VV values in one test case does not exceed 100100.
  • Time limit: 30 3 seconds.

Large dataset (20 Pts, Test set 2 - Hidden)

  • 1D1061 \leq D \leq 10^6
  • 1C2001 \leq C \leq 200.
  • The sum of all VV values does not exceed 10610^6.
  • Time limit: 60 6 seconds.