CF1622C.Set or Decrease

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given an integer array a1,a2,,ana_1, a_2, \dots, a_n and integer kk .

In one step you can

  • either choose some index ii and decrease aia_i by one (make ai=ai1a_i = a_i - 1 );
  • or choose two indices ii and jj and set aia_i equal to aja_j (make ai=aja_i = a_j ).

What is the minimum number of steps you need to make the sum of array i=1naik\sum\limits_{i=1}^{n}{a_i} \le k ? (You are allowed to make values of array negative).

输入格式

The first line contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

The first line of each test case contains two integers nn and kk ( 1n21051 \le n \le 2 \cdot 10^5 ; 1k10151 \le k \le 10^{15} ) — the size of array aa and upper bound on its sum.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ai1091 \le a_i \le 10^9 ) — the array itself.

It's guaranteed that the sum of nn over all test cases doesn't exceed 21052 \cdot 10^5 .

输出格式

For each test case, print one integer — the minimum number of steps to make i=1naik\sum\limits_{i=1}^{n}{a_i} \le k .

输入输出样例

  • 输入#1

    4
    1 10
    20
    2 69
    6 9
    7 8
    1 2 1 3 1 2 1
    10 1
    1 2 3 1 2 6 1 6 8 10

    输出#1

    10
    0
    2
    7

说明/提示

In the first test case, you should decrease a1a_1 1010 times to get the sum lower or equal to k=10k = 10 .

In the second test case, the sum of array aa is already less or equal to 6969 , so you don't need to change it.

In the third test case, you can, for example:

  1. set a4=a3=1a_4 = a_3 = 1 ;
  2. decrease a4a_4 by one, and get a4=0a_4 = 0 .

As a result, you'll get array [1,2,1,0,1,2,1][1, 2, 1, 0, 1, 2, 1] with sum less or equal to 88 in 1+1=21 + 1 = 2 steps.In the fourth test case, you can, for example:

  1. choose a7a_7 and decrease in by one 33 times; you'll get a7=2a_7 = -2 ;
  2. choose 44 elements a6a_6 , a8a_8 , a9a_9 and a10a_{10} and them equal to a7=2a_7 = -2 .

As a result, you'll get array [1,2,3,1,2,2,2,2,2,2][1, 2, 3, 1, 2, -2, -2, -2, -2, -2] with sum less or equal to 11 in 3+4=73 + 4 = 7 steps.

首页