#P1478. Apple Picking with Limited Energy

    ID: 14764 Type: Default 1000ms 256MiB

Apple Picking with Limited Energy

Apple Picking with Limited Energy

TaoTao's apple tree has produced nn apples this autumn. He now has a stool with height aa centimeters. When he cannot reach an apple with his bare arms (with maximum reach bb centimeters), he stands on the stool and tries again. However, due to previous efforts, his remaining energy is limited to ss. Each apple requires a certain amount of energy yiy_i to pick. The apples lie on the ground at heights xix_i. Note that TaoTao can only pick an apple if its height xix_i 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 yiy_i 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 ss.

inputFormat

The first line contains four integers nn, aa, bb, and ss, where nn is the number of apples, aa is the height of the stool, bb is the maximum reach of TaoTao when standing normally, and ss is the available energy. The second line contains nn integers x1,x2,,xnx_1, x_2, \dots, x_n, representing the heights (in centimeters) at which the apples lie on the ground. The third line contains nn integers y1,y2,,yny_1, y_2, \dots, y_n, where yiy_i is the energy required to pick the ii-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