CF1814D.Balancing Weapons

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You've got a job in a game studio that developed an online shooter, and your first big task is to help to balance weapons. The game has nn weapons: the ii -th gun has an integer fire rate fif_i and an integer damage per bullet did_i . The ii -th gun's total firepower is equal to pi=fidip_i = f_i \cdot d_i .

You have to modify the values did_i of some guns in such a way that the new values did_i will still be integers, and the firepower of all guns will become balanced. Given an integer kk , the guns are said to be balanced if max1inpimin1inpik\max\limits_{1 \le i \le n}{p_i} - \min\limits_{1 \le i \le n}{p_i} \le k .

Since gamers that play your game don't like big changes, you need to change the values did_i for the minimum possible number of guns. What is the minimum number of guns for which you have to change these values to make the guns balanced?

Note that the new values did_i must be integers greater than 00 .

输入格式

The first line contains a single integer tt ( 1t10001 \le t \le 1000 ) — the number of test cases.

The first line of each test case contains two integers nn and kk ( 2n30002 \le n \le 3000 ; 0k15000 \le k \le 1500 ) — the number of guns to balance, and the maximum allowed gap between the most and the least powerful weapons.

The second line contains nn integers f1,f2,,fnf_1, f_2, \dots, f_n ( 1fi20001 \le f_i \le 2000 ), where fif_i is the fire rate of the ii -th gun.

The third line contains nn integers d1,d2,,dnd_1, d_2, \dots, d_n ( 1di1091 \le d_i \le 10^9 ), where did_i is the damage per bullet of the ii -th gun.

It's guaranteed that the sum of nn over all test cases doesn't exceed 30003000 .

输出格式

For each test case, print the minimum number of guns which damage did_i you have to change in order to make the guns balanced.

Note that the new values did_i must be integers greater than 00 .

输入输出样例

  • 输入#1

    5
    4 2
    6 3 13 7
    1 2 1 2
    3 2
    100 101 102
    100 99 98
    5 0
    1 12 4 4 3
    12 1 3 3 4
    2 50
    1000 10
    1000000000 1
    3 5
    1 19 11
    49 4 72

    输出#1

    2
    3
    0
    1
    2

说明/提示

In the first test case, you can set d1=2d_1 = 2 and d2=4d_2 = 4 . You'll get an array d=[2,4,1,2]d = [2, 4, 1, 2] , and the values of firepower will be p=[12,12,13,14]p = [12, 12, 13, 14] . The guns are balanced, since 1412214 - 12 \le 2 .

In the second test case, you have to change the value did_i for all three guns. For example, you can set d=[5151,5100,5050]d = [5151, 5100, 5050] .

In the third test case, all guns are already balanced, so you don't have to change anything.

首页