#K54302. Maximizing Reachable Building Index

    ID: 29723 Type: Default 1000ms 256MiB

Maximizing Reachable Building Index

Maximizing Reachable Building Index

You are given a sequence of n buildings with varying heights. You have a limited number of ladders (l) and bricks (b). Your task is to determine the maximum building index that can be reached sequentially from the first building (index 0) by moving only to the next building in the sequence.

When moving from building i to building i+1, if the next building is taller, you must either use a ladder or use bricks equal to the difference in height. You should use the ladders to cover the largest height differences and bricks for the smaller ones. In case you do not have enough bricks to cover a required gap after using all available ladders, you must stop at the current building.

The problem can be formalized using the following reasoning:

For each increment from building i to building i+1, let \( d = \max(0, h_{i+1}-h_i) \). Given that you can use at most \( l \) ladders, you want to assign these ladders to the largest \( d \) values. The sum of the remaining \( d \) values (covered by bricks) should not exceed \( b \).

Determine the maximum index that can be reached under these constraints.

Input Format: The input is read from standard input in the format described below.

inputFormat

The first line contains three space-separated integers: n (the number of buildings), l (the number of ladders), and b (the number of bricks).

The second line contains n space-separated integers representing the heights of the buildings.

outputFormat

Output a single integer representing the maximum building index (0-indexed) that can be reached under the given constraints.

## sample
5 1 5
4 2 7 6 9
4