Klyukalo
InterviewTime limit1sMemory limit1024 MB
Find the fewest 1-gram weight changes that bring the total weighted deviation of N parts down to at most K.
Problem
A klyukalo has parts, and each part has a standard weight of grams. If part weighs grams in a given klyukalo, its deviation is . The deviation of the whole klyukalo is the sum of the deviations of all parts, . The allowed deviation is .
You are given a klyukalo. In one minute, you can either increase or decrease the weight of one part by 1 gram. What is the minimum time needed to bring the given klyukalo to the standard so that its deviation is at most ?
Input
The first line contains two integers and (, ), the number of parts and the allowed deviation.
The second line contains integers (), the standard weights of the parts.
The third line contains integers (), the weights of the parts in the given klyukalo.
Output
Print the minimum number of minutes needed to bring the given klyukalo to the standard with a deviation of at most .
Hint
In the example, you can reduce the weight of the first and third parts to their standards.