| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 2048 MB | 14 | 10 | 6 | 60.000% |
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 $n$ musical segments, where the $i$th musical segment has pitch intensity $a_i$ and is $b_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 $i$ where $a_{i-1} > a_i < a_{i+1}, 1 < i < n$) and do not take more than $k$ breaths in total.
Note:
The input consists of:
Output the longest time (in seconds) between two breaths, for an optimal performance of the song.
6 1 1 1 2 1 1 1 2 1 1 1 2 1
3
9 2 2 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 1
4