Under construction

Still being built. Things may change

Klyukalo

Interview

Time limit1sMemory limit1024 MB

Summary
Find the fewest 1-gram weight changes that bring the total weighted deviation of N parts down to at most K.
Level

Medium4 of 10

Topics
Greedy, Sorting, Math
Solved
No attempts yet

Problem

A klyukalo has NN parts, and each part ii has a standard weight of sis_i grams. If part ii weighs aia_i grams in a given klyukalo, its deviation is ∣ai−si∣si\frac{|a_i - s_i|}{s_i}. The deviation of the whole klyukalo is the sum of the deviations of all parts, ∑∣ai−si∣si\sum \frac{|a_i - s_i|}{s_i}. The allowed deviation is KK.

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 KK?

Input

The first line contains two integers NN and KK (1≤N≤1051 \le N \le 10^5, 0≤K≤1090 \le K \le 10^9), the number of parts and the allowed deviation.

The second line contains NN integers sis_i (1≤si≤101 \le s_i \le 10), the standard weights of the parts.

The third line contains NN integers aia_i (1≤ai≤1091 \le a_i \le 10^9), 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 KK.

Hint

In the example, you can reduce the weight of the first and third parts to their standards.

Examples1

  1. Example 1

    Input
    3 1
    1 2 1
    2 4 3
    
    Expected output
    3