#P1545. [USACO04DEC] Dividing the Path G

    ID: 8317 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp2004线段树USACO单调队列动态规划优化

[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 L (1L106)L\ (1\le L\le 10^6), and LL is guaranteed to be even. Each sprinkler sprays in both directions with a fixed radius that is at least AA and at most BB, where A,B (1AB103)A, B\ (1\le A\le B\le 10^3) 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 N (1N103)N\ (1\le N\le 10^3) cows, each with a favorite grass interval. The ii-th cow’s interval is [Si,Ei][S_i,E_i], 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:

  1. The number line for LL is labeled starting from 00 (i.e., the coordinate range is 0L0\sim L).
  2. Sprinkler coordinates and radii must be integers. For a sprinkler at coordinate ii with radius xx, its irrigation interval is [ix,i+x][i-x,i+x].
  3. The irrigated interval must lie within the ridge. For example, you cannot place a sprinkler with radius 11 at position 00.

Find the minimum number of sprinklers required.

Input Format

The first line contains two integers N,LN,L.

The second line contains two integers A,BA,B.

Then follow NN lines, each containing two integers Si,EiS_i,E_i1Si<EiL1\le S_i < E_i\le L).

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 1-1.

2 8
1 2
6 7
3 6
3

Hint

Constraints:

  • For 100%100\% of the testdata, 1L1061\le L\le 10^6, 1A,B1031\le A,B\le 10^3, 1N1031\le N\le 10^3, 1Si<EiL1\le S_i<E_i\le L.

Sample explanation:

Translated by ChatGPT 5