CF1622C Set or Decrease

题目描述

给你一个长度为 $n(1 \leq n \leq 2 \cdot 10^5)$ 的序列 $a_1,a_2,...,a_n(1 \leq a_i \leq 10^9)$ 和整数 $k(1 \leq k \leq 10^{15})$。 每一步你可以: 1. 选择一个下标 $i$ 使得 $a_i = a_i - 1$。 2. 或者选择两个下标 $i$ 和 $j$ 使得 $a_i =a_j$。 你需要求出最少在多少步之后,$\sum\limits_{i=1}^na_i \leq k$(你可以将一些元素减成负数)。

输入格式

输入的第一行包含一个整数 $t(1 \leq t \leq 10^4)$,表示样例的组数。 每组样例的第一行有两个整数 $n(1 \leq n \leq 2 \cdot 10^5)$ 和 $k(1 \leq k \leq 10^{15})$。 第二行则是数组的每一个元素。 保证所有 $n$ 的和小于等于 $2 \cdot 10^5$。

输出格式

输出一个整数,表示最少需要的步数。 translate by $__KrNalty__$ 2022.1.26

说明/提示

In the first test case, you should decrease $ a_1 $ $ 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: 1. set $ a_4 = a_3 = 1 $ ; 2. decrease $ a_4 $ by one, and get $ a_4 = 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: 1. choose $ a_7 $ and decrease in by one $ 3 $ times; you'll get $ a_7 = -2 $ ; 2. choose $ 4 $ elements $ a_6 $ , $ a_8 $ , $ a_9 $ and $ a_{10} $ and them equal to $ a_7 = -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.