#P1545. [USACO04DEC] Dividing the Path G
[USACO04DEC] Dividing the Path G
Description
John’s cows have discovered that the grass on the ridge is especially tasty. To sustain its growth, John plans to install several sprinklers.
To simplify the problem, the ridge is modeled as a one-dimensional number line of length , and is guaranteed to be even. Each sprinkler sprays in both directions with a fixed radius that is at least and at most , where are given positive integers. The interval within its radius on both sides of its position is its irrigation area.
The entire ridge must be irrigated, and irrigation areas of different sprinklers are not allowed to overlap. John has cows, each with a favorite grass interval. The -th cow’s interval is , and different cows’ intervals may overlap. Each cow’s favorite interval must be irrigated by exactly one sprinkler, i.e., it must be entirely contained in the irrigation range of a single sprinkler.
Note:
- The number line for is labeled starting from (i.e., the coordinate range is ).
- Sprinkler coordinates and radii must be integers. For a sprinkler at coordinate with radius , its irrigation interval is .
- The irrigated interval must lie within the ridge. For example, you cannot place a sprinkler with radius at position .
Find the minimum number of sprinklers required.
Input Format
The first line contains two integers .
The second line contains two integers .
Then follow lines, each containing two integers ().
Output Format
Output a single line with the minimum number of sprinklers required. If it is impossible to design a valid sprinkler configuration for Farmer John, output .
2 8
1 2
6 7
3 6
3
Hint
Constraints:
- For of the testdata, , , , .
Sample explanation:

Translated by ChatGPT 5
京公网安备 11011102002149号