#C3575. Maximize Minimum Energy Levels

    ID: 47017 Type: Default 1000ms 256MiB

Maximize Minimum Energy Levels

Maximize Minimum Energy Levels

You are given an array of positive integers representing the initial energy levels of N devices. You also have a budget of B extra energy units. Each energy unit can increase a device's energy level by 1. Your task is to distribute the energy optimally so that the minimum energy level among all devices is maximized.

Formally, given an array E = [e_1, e_2, \dots, e_N] and an integer B, find the maximum integer M such that after distributing some energy, every device has an energy level of at least M. Mathematically, you need to determine the maximum M satisfying:

[ \sum_{i=1}^{N} \max(0, M - e_i) \leq B ]

The input begins with an integer T denoting the number of test cases. For each test case, the first line contains two integers N and B. The second line contains N space-separated integers which are the initial energy levels of the devices.

inputFormat

The input is given via standard input (stdin) with the following format:

  1. The first line contains an integer T, the number of test cases.
  2. For each test case:
    1. The first line contains two space-separated integers N and B, where N is the number of devices and B is the energy budget.
    2. The second line contains N space-separated integers representing the initial energy levels of the devices.

outputFormat

For each test case, output a single line containing one integer — the maximum possible minimum energy level among all devices after optimally distributing the budget.

## sample
2
3 6
1 3 2
4 10
5 2 4 3
4

6

</p>