#P2698. [USACO12MAR] Flowerpot S

[USACO12MAR] Flowerpot S

题目描述

Farmer John has been having trouble making his plants grow, and needs your help to water them properly. You are given the locations of N raindrops (1 <= N <= 100,000) in the 2D plane, where y represents vertical height of the drop, and x represents its location over a 1D number line:

Each drop falls downward (towards the x axis) at a rate of 1 unit per second. You would like to place Farmer John's flowerpot of width W somewhere along the x axis so that the difference in time between the first raindrop to hit the flowerpot and the last raindrop to hit the flowerpot is at least some amount D (so that the flowers in the pot receive plenty of water). A drop of water that lands just on the edge of the flowerpot counts as hitting the flowerpot.

Given the value of D and the locations of the N raindrops, please compute the minimum possible value of W.

老板需要你帮忙浇花。给出 NN 滴水的坐标,yy 表示水滴的高度,xx 表示它下落到 xx 轴的位置。

每滴水以每秒 11 个单位长度的速度下落。你需要把花盆放在 xx 轴上的某个位置,使得从被花盆接着的第 11 滴水开始,到被花盆接着的最后 11 滴水结束,之间的时间差至少为 DD

我们认为,只要水滴落到 xx 轴上,与花盆的边沿对齐,就认为被接住。给出 NN 滴水的坐标和 DD 的大小,请算出最小的花盆的宽度 WW

输入格式

第一行 22 个整数 NNDD

接下来 NN 行每行 22 个整数,表示水滴的坐标 (x,y)(x,y)

输出格式

仅一行 11 个整数,表示最小的花盆的宽度。如果无法构造出足够宽的花盆,使得在 DD 单位的时间接住满足要求的水滴,则输出 1-1

4 5
6 3
2 4
4 10
12 15
2

提示

44 滴水,(6,3)(6,3)(2,4)(2,4)(4,10)(4,10)(12,15)(12,15) 。水滴必须用至少 55 秒时间落入花盆。花盆的宽度为 22 是必须且足够的。把花盆放在 x=46x=4\dots6 的位置,它可以接到 1133 水滴, 之间的时间差为 103=710-3=7 满足条件。

【数据范围】

40%40\% 的数据:1N10001 \le N \le 10001D20001 \le D \le 2000

100%100\% 的数据:1N1051 \le N \le 10 ^ 51D1061 \le D \le 10 ^ 60x,y1060\le x,y\le10^6