Cinema
Time limit2sMemory limit512 MB
Given rows of seat comfort values and a budget k for raising them, maximize the audiences seated, where each person takes the most comfortable reachable seat.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Stack, Binary search, Array
- Solved
- No attempts yet
Problem
The main movie theater of the city has a single auditorium with rows of padded seats. Each seat has a comfort value, which is a non-negative integer. A seat with a larger comfort value is more comfortable.
A row can only be entered from the left side of the auditorium. The seats in a row are numbered 1 to from left to right. When a person enters a row, they sit on the most comfortable seat that is free and accessible to them. If they sit at seat , every person who comes later is blocked from seats to . If several free and accessible seats tie for the highest comfort value, the person sits on the leftmost one.
The owner plans to raise the comfort values of some seats to attract more audiences. Raising a seat's comfort value by one unit costs a fixed amount. The total increase across all seats must not exceed . Find the way to raise comfort values by at most units in total that gives the maximum number of audiences in the auditorium.
Input
The first line contains three non-negative integers , , and , where is the number of rows, is the number of seats in each row, and is the total comfort increase allowed. The constraints are and .
Each of the next lines contains non-negative integers, each at most , giving the comfort values of the seats in that row from left to right.
Output
Print a single line containing the maximum number of audiences.