Eurovision

시간 제한1초메모리 제한2048 MB

요약
각 구간의 음높이와 길이가 주어질 때, 지역 최솟값에서만 최대 k번 숨을 쉬어 호흡 사이 최대 시간을 최소화하고 그 값을 출력한다.
난이도

보통10점 중 7점

유형
이분 탐색, 그리디, 동적 계획법, 누적 합
정답자
아직 제출이 없습니다

문제

It's that time of the year! Time again for Eurovision (and FPC)! Although, there is something rather special about this edition. In an unexpected turn of events, Delft was chosen to host Eurovision in the Aula. As you might expect, all tickets were sold out in a matter of seconds: students from all over Delft's faculties are eager to attend such a special event. Naturally, their enthusiasm is sparked by the same question: "What's the longest time a contestant has to sing without breathing, given that they breathe optimally?"

A song is divided into nn musical segments, where the iith musical segment has pitch intensity a_ia\_i and is b_ib\_i seconds in length. Each contestant sings these musical segments consecutively, with no pause in between, but will take some deep breaths at key moments (consider the time it takes to breathe negligible). To maintain a pleasing rhythm of music, performers only breathe immediately after a local minimum in pitch intensity (i.e., after a musical segment ii where a_i−1>a_i<a_i+1,1<i<na\_{i-1} > a\_i < a\_{i+1}, 1 < i < n) and do not take more than kk breaths in total.

Note:

  • Eurovision contestants have an inclination towards algorithmic thinking, and therefore, they all breathe optimally: within the constraints, the longest time between two breaths is as short as possible.
  • Naturally, a singer will breathe right before starting to sing and immediately after finishing, so these two breaths do NOT count towards the total number of breaths.

입력

The input consists of:

  • One line containing two integers: nn (1≤n≤1041\leq n\leq 10^4), the number of musical segments in the song, and kk (0≤k<n0\leq k < n), the maximum number of breaths that can be taken while performing the song.
  • nn lines containing two integers each, a_ia\_i and b_ib\_i (1≤a_i,b_i≤1091 \leq a\_i, b\_i \leq 10^9), the pitch and length (in seconds) of the iith musical segment.

출력

Output the longest time (in seconds) between two breaths, for an optimal performance of the song.

예제2

  1. 예제 1

    입력
    6 1
    1 1
    2 1
    1 1
    2 1
    1 1
    2 1
    
    예상 출력
    3
    
  2. 예제 2

    입력
    9 2
    2 1
    1 1
    2 1
    1 1
    2 1
    1 1
    2 1
    1 1
    2 1
    
    예상 출력
    4