cswork / OAOpen practice workspace

AmazonOA #59

Get Maximum Credits (Dispatch Strategy)

Estimated MediumJudge-ready

Topics (AI-labelled)GreedyBits & Math

At each warehouse you subtract dispatch1 first, then your colleague subtracts dispatch2, alternating until the stock is ≤0; whoever dispatches last gets the reward. The colleague may skip their own turn, at most skips times in total across all warehouses. Find the maximum number of warehouses you can win.

Input

The first line contains n dispatch1 dispatch2 skips (1≤n≤100000, the others 1..10⁹); the second line contains n stock values (1..10⁹).

Output

Output a single integer answer.

Example 1

Input:

3 2 3 1
3 6 2

Output:

3

Example 2

Input:

1 2 3 1
2

Output:

1

Example 3

Input:

2 1 4 1
5 5

Output:

0

Example notes

Example 1: stocks 6 and 2 need no skips and you dispatch last at both; stock 3 can also be won with 1 skip, so you can actually win 3, and the source answer 2 overlooked the available skip. Example 2: the first turn empties it directly, winning 1. Example 3: each warehouse needs 4 skips and a budget of 1 is not enough, so the answer is 0.

Editorial

Loading solution…