Logo
(追記) (追記ここまで)

32453번 - Effcient Slabstones Rearrangement 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB36242365.714%

문제

Barbara has a garden. The garden is long and narrow, divided into $m$ equal-sized regions arranged in a row. Her friend, Babara, gave her $n$ slabstones as birthday present. Barbara then placed these slabstones in her garden, so she can enjoy stepping slabstones from one to another every day. The $i$-th slabstone fully occupies the $l_i$-th to $r_i$-th region of the garden. The slabstones do not overlap, and any two slabstones have at least $d$ empty regions between them.

Below is a valid placement of the slabstones with $m = 15,ドル $n = 3,ドル $d = 2,ドル and the three slabstones occupy the regions 2ドル-4,ドル 7ドル-7,ドル 12ドル-13$ respectively.

Barbara recently bought another slabstone that will occupy $x$ consecutive regions in her garden. She will shift the original slabstones within the garden, then place the new slabstone somewhere in the garden. After shifting the original slabstones and placing the new slabstone, the slabstones cannot overlap, and any two slabstones must have at least $d$ empty regions between them. The slabstones should remain non-overlapping during slabstone rearrangement.

Shifting a single slabstone to an adjacent region takes one minute. For example, the above rearrangement process takes 4ドル$ minutes. Now Barbara wants to know the minimum possible total time required to rearrange the slabstones, so she can save time for “other purposes”.

입력

The first line contains four integers $n,ドル $m,ドル $d$ and $x$. The $i$-th of the following $n$ lines contains two integers $l_i$ and $r_i$.

출력

The minimum possible total time (in minutes) to rearrange the slabstones so the new slabstone can be placed in the garden. If the new slabstone cannot be placed in the garden no matter how the slabstones are rearranged, just output -1.

제한

  • 1ドル ≤ n ≤ 2000$
  • 1ドル ≤ d ≤ m ≤ 10^9$
  • 1ドル ≤ x ≤ m ≤ 10^9$
  • 1ドル ≤ l_i ≤ r_i ≤ m$ for $i \in \{1, 2,\dots ,n\}$
  • $r_i + d + 1 ≤ l_i+1$ for $i \in \{1, 2,\dots ,n - 1\}$. That is, the slabstones are given in order from left to right.

예제 입력 1

3 15 2 3
2 4
7 7
12 13

예제 출력 1

4

예제 입력 2

5 100 1 75
2 3
5 7
11 13
17 19
23 29

예제 출력 2

9

예제 입력 3

1 100 99 1
1 1

예제 출력 3

-1

힌트

출처

ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2024 E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /