All problems

Problem 976

Maximum Bags With Full Capacity of Rocks

Medium · 20 pts · Array, Greedy, Sorting

Problem

Bag i can hold CAPACITY[i] rocks and already contains ROCKS[i] rocks. You have ADDITIONAL extra rocks to place in any bags. Maximise the number of completely full bags. Each bag needs CAPACITY[i] - ROCKS[i] more rocks to be full, so sort those needs from smallest to largest and fill bags in that order while the extra rocks last.

Input

The first line contains N and ADDITIONAL. The second line contains the capacities. The third line contains the current rocks.

Output

Print the maximum number of full bags.

Constraints

1 <= N <= 50000; 1 <= CAPACITY[i] <= 10^9; 0 <= ROCKS[i] <= CAPACITY[i]; 1 <= ADDITIONAL <= 10^9

Example input

4 2
2 3 4 5
1 2 4 4

Example output

3

Explanation

With capacities 2 3 4 5, rocks 1 2 4 4 and 2 extra rocks, the needs are 1, 1, 0 and 1. Fill the full bag (0) and two bags needing 1, making 3 full bags.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Minimum Operations to Make the Array Increasing Next: Minimum Rounds to Complete All Tasks