#P10762. [BalticOI 2024] Fire

[BalticOI 2024] Fire

Background

Translated from BalticOI 2024 Day2 T1.

Problem Description

We divide one day into MM time units. There are NN people, and person ii is willing to work during [si,ei)[s_i, e_i). If si>eis_i > e_i, it means this person is willing to work until time eie_i on the next day. Each person’s maximum continuous working time does not exceed one full day.

You need to arrange some people to work so that their working time can cover the whole day. Find the number of people needed.

Input Format

The first line contains two integers N,MN, M.

The next NN lines each contain a pair (si,ei)(s_i, e_i).

Output Format

Output one integer, the minimum number of people to arrange. If it is impossible to arrange people so that the whole day is covered, output 1-1.

4 100
10 30
30 70
20 40
60 20
3
1 100
30 40
-1

Hint

For the first sample, choose 1,2,41, 2, 4.

For the second sample, there is clearly no solution.

Subtask ID Special Property Score
11 N20N \leq 20 1414
22 N300N \leq 300 1717
33 N5000N \leq 5000 99
44 Guaranteed si<eis_i < e_i or ei=0e_i = 0 1313
55 Guaranteed that everyone has the same working time interval 2121
66 No special property 2626

For all testdata, 1N2×1051 \leq N \leq 2 \times 10^5, 2M1092 \leq M \leq 10^9, 0si,ei<M0 \leq s_i, e_i < M, sieis_i \ne e_i.

Translated by ChatGPT 5