Planine
Time limit2sMemory limit512 MB
Given a mountain profile of alternating peaks and valleys at height below h, find the minimum number of fairies at height h needed so every valley is visible from some fairy.
- Level
Medium7 of 10
- Topics
- Greedy, Geometry, Implementation
- Solved
- No attempts yet
Problem
Zoran wanders across his Dalmatian homeland to forget his love woes. He comes across a mountain of a specific shape, behind which a young maiden is waiting for him. The mountain is described by alternating low and high points, where 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 . A fairy illuminates a 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 that can illuminate all the valleys simultaneously?
Input
The first line contains two integers (, odd) and (), the number of points describing the mountain and the height the fairies live at.
The -th of the following lines contains integers and (, ), the coordinates of the -th point of the mountain.
It is guaranteed that , and , , , , .
Output
Print the least number of fairies such that all valleys are illuminated.
Hint
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 in the figure below.