Problem list
Log in
#coci00582 · COCI 2020/2021 Contest 5

Planine

Diamond V 2.0 s 512 MB

Zoran wanders across his Dalmatian homeland to forget his love woes. He came across a mountain of a specific shape, behind which a young maiden is waiting for him. The mountain can be described with $n$ alternating low and high points, where $n$ is odd. Points at odd indices, except the first and the last point, are called valleys. Zoran is afraid of the dark. Even the call of love will not give him courage to cross the mountain at night. As usual, the fairies of Velebit come to the rescue. We model each fairy by a luminous dot at a fixed height $h$. A fairy illuminates the valley if and only if the segment connecting the fairy and the valley does not intersect the interior of the mountain. The mountain from the first example, and a fairy illuminating all three valleys. What is the least number of fairies which can illuminate all the valleys simulaneously?

Input

The first line contains two integers $n$ ($3 \le n < 10^{6}$, $n$ odd) and $h$ ($1 \le h \le 10^{6}$), the number of points describing the mountain and the height the fairies live at. The $i$-th of the following $n$ lines contains integers $x_{i}$ and $y_{i}$ (−$10^{6} \le x_{i} \le 10^{6}$, $0 \le y_{i} < h$), the coordinates of the $i$-th point of the mountain. It is guaranteed that $x_{1} < x_{2}$ < · · · < $x_{n}$, and $y_{1} < y_{2}$, $y_{2} > y_{3}$, $y_{3} < y_{4}$, . . ., $y_{n - 1} > y_{n}$.

Output

Output the least number of fairies such that all valleys are illuminated.

Example 1

Input
9 6
0 0
1 2
3 0
6 3
8 1
9 2
11 1
12 4
14 0
Output
1

Example 2

Input
9 5
-5 2
-4 3
-2 1
0 4
2 2
3 3
4 1
5 2
6 1
Output
2

Clarification of the examples: The first example is shown in the statement. It can be shown that the valleys in the second example cannot be illuminated using only one fairy. An example with two fairies is given on the figure below.

Source
COCI 2020/2021 Contest 5
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code