CF1622C.Set or Decrease
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer array a1,a2,…,an and integer k .
In one step you can
- either choose some index i and decrease ai by one (make ai=ai−1 );
- or choose two indices i and j and set ai equal to aj (make ai=aj ).
What is the minimum number of steps you need to make the sum of array i=1∑nai≤k ? (You are allowed to make values of array negative).
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases.
The first line of each test case contains two integers n and k ( 1≤n≤2⋅105 ; 1≤k≤1015 ) — the size of array a and upper bound on its sum.
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤109 ) — the array itself.
It's guaranteed that the sum of n over all test cases doesn't exceed 2⋅105 .
输出格式
For each test case, print one integer — the minimum number of steps to make i=1∑nai≤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 a1 10 times to get the sum lower or equal to k=10 .
In the second test case, the sum of array a is already less or equal to 69 , so you don't need to change it.
In the third test case, you can, for example:
- set a4=a3=1 ;
- decrease a4 by one, and get a4=0 .
As a result, you'll get array [1,2,1,0,1,2,1] with sum less or equal to 8 in 1+1=2 steps.In the fourth test case, you can, for example:
- choose a7 and decrease in by one 3 times; you'll get a7=−2 ;
- choose 4 elements a6 , a8 , a9 and a10 and them equal to a7=−2 .
As a result, you'll get array [1,2,3,1,2,−2,−2,−2,−2,−2] with sum less or equal to 1 in 3+4=7 steps.