For this Question: Given an integer array <b>arr</b> and a target value <b>K</b>. Print the minimum integer value <b>V</b> such that when we change all values greater than V in the array to V, <b>the absolute difference (|sum - K|) between the sum of the array elements and K is minimized.</b>

Note: the answer is not necessarily a number from arr.The input line containing T, denoting the number of testcases. Each testcase contains 2 lines. First line contains N, size of array and target K separated by space. Second line contains elements of array.

Constraints:
1 <= T <= 50
1 <= N <= 10^4
1 <= arr[i], K <= 10^5For each testcase you need to print the minimum such integer possible in a new line.Input:
2
3 10
4 9 3
3 10
2 3 5

Output:
3
5

Explanation:
Testcase 1: When using 3 arr converts to [3, 3, 3] which sums 9 and that's the optimal answer., I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;

class Main
{
    public static void main(String args[])throws IOException
    {
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(read.readLine());


        while(t-- > 0)
        {

            String str[] = read.readLine().trim().split(" ");
            int N = Integer.parseInt(str[0]);
            int K = Integer.parseInt(str[1]);


            //`int D = Integer.parseInt(str[1]);

            int arr[] = new int[N];
            str = read.readLine().trim().split(" ");
            for(int i = 0; i < N; i++)
                arr[i] = Integer.parseInt(str[i]);

            //int res[] = moveZeroes(arr);
            //print(res);
            System.out.println(findBestValue(arr, K));

        }
    }

    static void print(int list[])
    {
        for(int i = 0; i < list.length; i++)
            System.out.print(list[i] + " ");

    }

    static int findBestValue(int arr[], int target) {
        int sum = 0;
        int mx = Integer.MIN_VALUE;
        int sz = arr.length;
        int remaining_target = target;
        int remaining_items = sz;
        int one_part = target / sz;

        for(int i = 0; i < sz; ++i) {
            mx = Math.max(mx, arr[i]);
            sum += arr[i];

            if(arr[i] < one_part) {
                remaining_items--;
                remaining_target -= arr[i];
            }
        }

        if(sum <= target) {
            return mx;
        }

        int val1 = remaining_target / remaining_items;

        int min_val = val1 - 1;
        int min_diff = Math.abs(remaining_target - (min_val * remaining_items));

        int diff1 = Math.abs(remaining_target - (val1 * remaining_items));
        if(diff1 < min_diff) {
            min_val = val1;
            min_diff = diff1;
        }

        int val2 = val1 + 1;
        int diff2 = Math.abs(remaining_target - (val2 * remaining_items));
        return (diff2 < min_diff) ? val2 : min_val;
    }



}, In this Programming Language: Java, Now tell me if this Code is compilable or not?