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

31971번 - Fire 서브태스크다국어

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

문제

In the old Baltic religion, it is important to have a holy fire burning. A priest called krivis is responsible for protecting it from extinguishing. He has many trustworthy helpers called vaidilutės, and wants to create a schedule for them to stoke and protect the fire. He has to ensure that the fire is always maintained by some vaidilutė.

Krivis has his own time measurement system, where each day has $M$ minutes. There are $N$ vaidilutės in his village. The $i$-th vaidilutė's possible work time are described by two integers $s_i$ and $e_i$. The number $s_i$ is her own earliest time in the day when she may start working, and the number $e_i$ is the latest time of the day when she needs to finish working. Time is counted in minutes from the start of the day. Note that when $s_i > e_i,ドル the vaidilutė is willing to work overnight.

Krivis asked you to choose some vaidilutės and arrange shifts for them. A chosen vaidilutė must start her shift not earlier than time $s_i,ドル and end her shift not later than $e_i$. A single shift is always shorter than the whole day. The chosen vaidilutės will repeat their shifts everyday.

Handing things over from one vaidilutė to the next increases the risk of the fire extinguishing. Because of this, you want to minimize the number of times this happens during the day and will arrange a schedule where the smallest possible number of vaidilutės is needed.

Calculate the minimum number of vaidilutės that you need to choose, such that the holy fire is maintained at all times.

입력

The first line contains two integers $N$ and $M$ – the number of vaidilutės available and the length of the day in minutes.

Then $N$ lines follow. The $i$-th of them contains two integers $s_i$ and $e_i$ – the earliest starting time and the latest finishing time of the $i$-th vaidilutė.

출력

Output one integer – the minimum number of vaidilutės you need to choose. If it is impossible to choose the vaidilutės according to the requirements, output $-1$.

제한

  • 1ドル ≤ N ≤ 2 \cdot 10^5$
  • 2ドル ≤ M ≤ 10^9$
  • 0ドル ≤ s_i , e_i < M$ (for all 1ドル ≤ i ≤ N$)
  • $s_i \ne e_i$ (for all 1ドル ≤ i ≤ N$)

서브태스크

번호배점제한
114

$N ≤ 20$.

217

$N ≤ 300$.

39

$N ≤ 5,円 000$.

413

For all vaidilutės, $s_i < e_i$ or $e_i = 0$.

521

For each vaidilutė, the time interval from time $s_i$ until time $e_i$ has the same length.

626

No additional constraints.

예제 입력 1

4 100
10 30
30 70
20 40
60 20

예제 출력 1

3

You can choose the 1ドル$-st, 2ドル$-nd and 4ドル$-th vaidilutės and arrange their shifts as follows:

  • 1ドル$-st vaidilutė works from the 10ドル$-th minute until the 30ドル$-th minute.
  • 2ドル$-nd vaidilutė works from the 30ドル$-th minute until the 70ドル$-th minute.
  • 4ドル$-th vaidilutė works from the 70ドル$-th minute until the 10ドル$-th minute on the following day.

예제 입력 2

1 100
30 40

예제 출력 2

-1

It is impossible to make a schedule since there is only one vaidilutė and she cannot work the whole day.

힌트

출처

Olympiad > Baltic Olympiad in Informatics > BOI 2024 D번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

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

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