#P1478. Apple Picking with Limited Energy
Apple Picking with Limited Energy
Apple Picking with Limited Energy
TaoTao's apple tree has produced apples this autumn. He now has a stool with height centimeters. When he cannot reach an apple with his bare arms (with maximum reach centimeters), he stands on the stool and tries again. However, due to previous efforts, his remaining energy is limited to . Each apple requires a certain amount of energy to pick. The apples lie on the ground at heights . Note that TaoTao can only pick an apple if its height satisfies $$x_i \leq b \quad \text{or} \quad (b < x_i \leq a+b).$$ In other words, an apple is reachable if $$x_i \leq a+b.$$ Among all reachable apples, each one costs energy to pick. TaoTao wishes to pick as many apples as possible before his energy falls below zero. Determine the maximum number of apples he can pick so that the total energy consumed does not exceed .
inputFormat
The first line contains four integers , , , and , where is the number of apples, is the height of the stool, is the maximum reach of TaoTao when standing normally, and is the available energy. The second line contains integers , representing the heights (in centimeters) at which the apples lie on the ground. The third line contains integers , where is the energy required to pick the -th apple.
outputFormat
Output a single integer representing the maximum number of apples that TaoTao can pick without his energy dropping below zero.
sample
5 10 5 10
3 10 15 20 14
1 2 3 4 5
3