Weed Whacking
It's spring time, and you're getting ready to plant your next batch of crops for an autumn harvest. Before any seeds can be planted though, there are a lot of weeds in the field that must be dealt with. Most farmers would get a barrel of herbicide and spray it onto their field, but you want to keep things organic.
So instead, you purchase the WeedWiper 6900 from Agro-Urban Crop Protection Limited (AUCPL) to take care of the pesky weeds. They were dirt cheap, so you buy one hoping to whack away the weeds in no time.
However, those weed whackers were cheap for a reason: they can only cut up to a certain height, and they can only destroy one weed every second. Ugh! Begrudgingly, you get to work in creating a program to calculate the order you should wack your weeds in, to destroy as many as possible before they get out of control.
Input
The first line consists of integers
and
— the number of weeds and the maximum weed height your weed whacker can whack, respectively.
The next line contains space-separated integers
, the initial height of the
th weed.
The next line contains space-separated integers
, the growth rates of the
th weed. The growth rate is how much the weed grows in each second.
Output
Output a single integer, the maximum number of weeds you can whack.
Clarification
- You start whacking weeds at
seconds, where the weeds are at their initial height.
- You can only whack one weed at a time in each second.
- Once you whack away the weed, it will not regrow.
Example
Input 1
5 50
10 20 30 40 50
2 2 4 10 1
Output 1
5
You can whack all of the weeds before they get too high to whack.
Input 2
4 10
7 7 7 7
1 2 3 4
Output 2
3
- In the first second, destroy the last weed. The remaining weeds have heights of
8 9 10
. - In the second second, destroy the third weed. The remaining weeds have heights of
9 11
. - In the third second, destroy the first weed. The remaining weeds have heights of
13
.
The second weed is taller than 10
units, so it can't be destroyed anymore. It can be shown that 3
is the maximum number of weeds you can destroy.
Comments