Eurovision
Time limit1sMemory limit2048 MB
Given segments with pitch and duration, pick at most k breath points after local minima to minimize the longest breath-free stretch in seconds.
- Level
Medium6 of 10
- Topics
- Binary search, Greedy, Array
- Solved
- No attempts yet
Statement
Eurovision is held in the Aula in Delft this year, since Delft was chosen as the host. All tickets sold out within seconds. Students from all of Delft's faculties want to attend, and they are asking the same question: what is the longest time a contestant has to sing without breathing, if the contestant breathes optimally?
A song is divided into musical segments. The th segment has pitch intensity and lasts seconds. A contestant sings the segments one after another with no pause in between, but takes breaths at certain moments. Breathing takes negligible time. A contestant breathes only immediately after a local minimum in pitch intensity, meaning after segment with and . A contestant takes at most breaths in total.
Contestants breathe optimally: within the constraints, the longest time between two breaths is as short as possible.
A singer breathes right before starting and right after finishing. These two breaths do not count toward the total number of breaths.
Input
The input consists of:
- One line containing two integers: (), the number of musical segments, and (), the maximum number of breaths.
- lines each containing two integers and (), the pitch intensity and length in seconds of the th segment.
Output
Output the longest time in seconds between two breaths for an optimal performance.