It's Halloween again, and Alice got a whole slew of candy for her many candy-dependent children. It's a lucky time for her too, because she was just running out of all of her Halloween candy, and she wants to ration her current stock to keep her children alive for as long as possible.
Each child has a metabolism level and a hunger level . At the beginning of each day, their hunger level will decrease by 1 and Alice can choose to feed exactly children. Whenever she feeds a child, she will replenish them with calories, increasing their hunger level by their metabolism level . If at the end of the day, any child has hunger level , then they die. Before the beginning of the first day, before their hunger level decreases, each child's satisfies .
Alice has children, and she wants to keep them all alive for full days (that means there are day beginnings and day ends!), but that may not be possible! So, can you tell her what the maximum number of babies she can keep alive for full days is?
Constraints
For all subtasks:
Batch 1 [20%]
Batch 2 [80%]
Input Specifications
The first line will contain two integers and .
The next line will contain integers, the -th of which corresponds to .
Output Specification
One line with one integer, the maximum number of babies that can be kept alive for full days.
Sample Input
6 4
1 1 1 1 1 1
Sample Output
3
Sample Explanation
If you choose 3 children and feed them every day, then you can keep them alive indefinitely.
Sample Input
6 2
1 3 2 1 1 2
Sample Output
5
Sample Explanation
Take children 2 to 6. The values of and are outlined below:
3 | 2 | 1 | 1 | 2 | |
---|---|---|---|---|---|
3 | 2 | 1 | 1 | 2 |
On the first day, they each lose one hunger level. Feed the last three children to increase their hunger levels.
3 | 2 | 1 | 1 | 2 | |
---|---|---|---|---|---|
2 | 1 | 0 | 0 | 1 | |
2 | 1 | 1 | 1 | 3 |
On the second day, they each lose one hunger level. Feed the middle three children to increase their hunger levels.
3 | 2 | 1 | 1 | 2 | |
---|---|---|---|---|---|
1 | 0 | 0 | 0 | 2 | |
1 | 1 | 1 | 1 | 2 |
After the second day, they each have over hunger levels, so it is possible to feed 5 children.
If, instead, she took all 6, then at the end of 2 days there would be at least one baby that doesn't have enough food.
1 | 3 | 2 | 1 | 1 | 2 | Comments | |
---|---|---|---|---|---|---|---|
1 | 3 | 2 | 1 | 1 | 2 | Initial | |
0 | 2 | 1 | 0 | 0 | 1 | Day 1: their hunger levels decrease by 1 | |
1 | 2 | 1 | 1 | 1 | 1 | Day 1: you must feed the children with 0 hunger levels so they end the day with a positive amount | |
0 | 2 | 0 | 0 | 0 | 0 | Day 2: their hunger levels decrease by 1 |
No matter how you feed them, at the end of day two, at least one child will have a hunger level of .
Comments