description: You are given an integer array a_1, a_2, ..., a_n and integer k.
  
  In one step you can 
  
    * either choose some index i and decrease a_i by one (make a_i = a_i - 1); 
    * or choose two indices i and j and set a_i equal to a_j (make a_i = a_j). 
  
  
  
  What is the minimum number of steps you need to make the sum of array ∑_{i=1}^{n}{a_i} ≤ k? (You are allowed to make values of array negative).
  
  Input
  
  The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
  
  The first line of each test case contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 10^{15}) — the size of array a and upper bound on its sum.
  
  The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself.
  
  It's guaranteed that the sum of n over all test cases doesn't exceed 2 ⋅ 10^5.
  
  Output
  
  For each test case, print one integer — the minimum number of steps to make ∑_{i=1}^{n}{a_i} ≤ k.
  
  Example
  
  Input
  
  
  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
  
  
  Output
  
  
  10
  0
  2
  7
  
  Note
  
  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.
solution: import java.io.OutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.PrintWriter;
  import java.util.Arrays;
  import java.util.stream.LongStream;
  import java.util.InputMismatchException;
  import java.io.IOException;
  import java.util.Random;
  import java.io.InputStream;
  
  /**
   * Built using CHelper plug-in
   * Actual solution is at the top
   *
   * @author dauom
   */
  public class Main {
    public static void main(String[] args) {
      InputStream inputStream = System.in;
      OutputStream outputStream = System.out;
      InputReader in = new InputReader(inputStream);
      PrintWriter out = new PrintWriter(outputStream);
      CSetOrDecrease solver = new CSetOrDecrease();
      int testCount = Integer.parseInt(in.next());
      for (int i = 1; i <= testCount; i++)
        solver.solve(i, in, out);
      out.close();
    }
  
    static class CSetOrDecrease {
      public final void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        long k = in.nextLong();
        long[] a = in.nextLongArray(n);
        long sum = LongStream.of(a).sum();
        if (sum <= k) {
          out.println("0");
          return;
        }
        ArraySorter.javaSort(a);
  
        long ans = sum - k, lo = 1, hi = ans - 1, mid;
        while (lo <= hi) {
          mid = (lo + hi) >> 1;
          if (check(mid, sum, k, n, a)) {
            ans = mid;
            hi = mid - 1;
          } else {
            lo = mid + 1;
          }
        }
        out.println(ans);
      }
  
      private boolean check(final long steps, final long sum, final long k, final int n, final long[] a) {
        long f = a[0] - steps;
        long ans = sum - a[0] + f;
        long suffix = a[0];
        for (int i = 2; i <= Long.min(steps + 1, n); i++) {
          suffix += a[n - i + 1];
          ans = Long.min(ans, sum - suffix + i * ++f);
        }
        return ans <= k;
      }
  
    }
  
    static final class InputReader {
      private final InputStream stream;
      private final byte[] buf = new byte[1 << 18];
      private int curChar;
      private int numChars;
  
      public InputReader() {
        this.stream = System.in;
      }
  
      public InputReader(final InputStream stream) {
        this.stream = stream;
      }
  
      private int read() {
        if (this.numChars == -1) {
          throw new UnknownError();
        } else {
          if (this.curChar >= this.numChars) {
            this.curChar = 0;
  
            try {
              this.numChars = this.stream.read(this.buf);
            } catch (IOException ex) {
              throw new InputMismatchException();
            }
  
            if (this.numChars <= 0) {
              return -1;
            }
          }
  
          return this.buf[this.curChar++];
        }
      }
  
      public final int nextInt() {
        int c;
        for (c = this.read(); isSpaceChar(c); c = this.read()) {
        }
  
        byte sgn = 1;
        if (c == 45) { // 45 == '-'
          sgn = -1;
          c = this.read();
        }
  
        int res = 0;
  
        while (c >= 48 && c <= 57) { // 48 == '0', 57 == '9'
          res *= 10;
          res += c - 48; // 48 == '0'
          c = this.read();
          if (isSpaceChar(c)) {
            return res * sgn;
          }
        }
  
        throw new InputMismatchException();
      }
  
      public final long nextLong() {
        int c;
        for (c = this.read(); isSpaceChar(c); c = this.read()) {
        }
  
        byte sgn = 1;
        if (c == 45) { // 45 == '-'
          sgn = -1;
          c = this.read();
        }
  
        long res = 0;
  
        while (c >= 48 && c <= 57) { // 48 == '0', 57 == '9'
          res *= 10L;
          res += c - 48; // 48 == '0'
          c = this.read();
          if (isSpaceChar(c)) {
            return res * sgn;
          }
        }
        throw new InputMismatchException();
      }
  
      public final String next() {
        int c;
        while (isSpaceChar(c = this.read())) {
        }
  
        StringBuilder result = new StringBuilder();
        result.appendCodePoint(c);
  
        while (!isSpaceChar(c = this.read())) {
          result.appendCodePoint(c);
        }
  
        return result.toString();
      }
  
      private static boolean isSpaceChar(final int c) {
        return c == 32 || c == 10 || c == 13 || c == 9
            || c == -1; // 32 == ' ', 10 == '\n', 13 == '\r', 9 == '\t'
      }
  
      public final long[] nextLongArray(final int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
          arr[i] = nextLong();
        }
        return arr;
      }
  
    }
  
    static class ArraySorter {
      private ArraySorter() {
        throw new RuntimeException("DON'T");
      }
  
      public static void javaSort(long[] a) {
        ArrayShuffler.shuffle(a);
        Arrays.sort(a);
      }
  
    }
  
    static class ArrayShuffler {
      private static Random r = new Random(System.nanoTime() * 21);
  
      private ArrayShuffler() {
        throw new RuntimeException("DON'T");
      }
  
      public static long[] shuffle(long[] arr, int from, int to) {
        int n = to - from + 1;
        for (int i = from; i <= to; i += 4) {
          int p = r.nextInt(n + 1) + from;
          if (p <= to) {
            long temp = arr[i];
            arr[i] = arr[p];
            arr[p] = temp;
          }
        }
        return arr;
      }
  
      public static long[] shuffle(long[] arr) {
        return shuffle(arr, 0, arr.length - 1);
      }
  
    }
  }
  
  