#P2736. CD Song Selection

    ID: 15999 Type: Default 1000ms 256MiB

CD Song Selection

CD Song Selection

You have just inherited the copyrights of NN unpublished songs recorded by the popular Broken Gong Rock band. You plan to release them on MM CDs. Each CD can hold at most TT minutes of music, and a song cannot be split between two CDs. You do not necessarily need to use all MM 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:

  1. 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.
  2. 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 NN, MM, and TT (1N,M,T201 \le N, M, T \le 20).
The second line contains NN integers, where the ii-th integer represents the duration of the ii-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