#C1433. Seating Participants with Comfort Constraints

    ID: 43967 Type: Default 1000ms 256MiB

Seating Participants with Comfort Constraints

Seating Participants with Comfort Constraints

In this problem, you are given (n) participants and (m) available seating slots arranged in a row. Each participant has a comfort level (c); for a participant to be seated, they require a contiguous block of (c+1) unoccupied seats. The goal is to determine the maximum number of participants that can be seated such that each seated participant’s comfort requirement is satisfied.

Formally, for a participant with comfort level (c), they need seats in positions (i, i+1, \ldots, i+c) (a total of (c+1) seats) where all these seats are free. To maximize seat utilization, it is optimal to seat participants in increasing order of their comfort requirements.

inputFormat

The input is read from standard input (stdin). The first line contains two space-separated integers (n) and (m), representing the number of participants and the number of seating slots, respectively. The second line contains (n) space-separated integers denoting the comfort level requirement for each participant.

outputFormat

Output a single integer to standard output (stdout) representing the maximum number of participants that can be seated while satisfying their comfort requirements.## sample

3 10
1 2 1
3

</p>