#P2736. CD Song Selection
CD Song Selection
CD Song Selection
You have just inherited the copyrights of unpublished songs recorded by the popular Broken Gong Rock band. You plan to release them on CDs. Each CD can hold at most minutes of music, and a song cannot be split between two CDs. You do not necessarily need to use all CDs.
Since you are a fan of classical music and are unsure about the artistic value of these songs, you decide to choose the songs according to the following criteria:
- The selected songs must appear in chronological order across all CDs. In other words, if the last song on the $i$-th CD was created at a certain time, then the first song on the $(i+1)$-th CD must have been created later.
- You want to maximize the total number of selected songs.
Given the duration (in minutes) of each song in chronological order, determine the maximum number of songs you can select and distribute among the CDs while adhering to the CD capacity constraints and the ordering rule.
inputFormat
The input consists of two lines:
The first line contains three integers , , and ().
The second line contains integers, where the -th integer represents the duration of the -th song in minutes (given in chronological order).
outputFormat
Output a single integer representing the maximum number of songs that can be selected and arranged on the CDs under the given constraints.
sample
5 2 10
3 4 5 6 1
4