| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 36 | 24 | 23 | 65.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.
3 15 2 3 2 4 7 7 12 13
4
5 100 1 75 2 3 5 7 11 13 17 19 23 29
9
1 100 99 1 1 1
-1
ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2024 E번