AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

FPC22-006.Eurovision

Easy · 1 s · 256 MB

  • icpc
  • fpc
  • 2022

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 nnn musical segments, where the iiith musical segment has pitch intensity aia_iai​ and is bib_ibi​ 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 iii where ai−1>ai<ai+1,1<i<na_{i-1} > a_i < a_{i+1}, 1 < i < nai−1​>ai​<ai+1​,1<i<n) and do not take more than kkk 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.

Giriş formatı

The input consists of:

• One line containing two integers: nnn (1≤n≤1041\leq n\leq 10^41≤n≤104), the number of musical segments in the song, and kkk (0≤k<n0\leq k < n0≤k<n), the maximum number of breaths that can be taken while performing the song.

• nnn lines containing two integers each, aia_iai​ and bib_ibi​ (1≤ai,bi≤1091 \leq a_i, b_i \leq 10^91≤ai​,bi​≤109), the pitch and length (in seconds) of the iiith musical segment.

Çıxış formatı

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

Qeyd

Source: Freshmen Programming Contest 2022 · Author: Jeroen Op de Beek and Dragos-Paul Vecerdea · License: CC BY-SA 4.0 · Original: https://fpc.wisv.ch · Statement adapted for AlgoLens and shared under the same license.

Nümunələr

Giriş #1

6 1
1 1
2 1
1 1
2 1
1 1
2 1

Çıxış #1

3

Giriş #2

9 2
2 1
1 1
2 1
1 1
2 1
1 1
2 1
1 1
2 1

Çıxış #2

4