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: def findBestValue(arr,target):
        org_sum=sum(arr)
        if org_sum<target:
            return max(arr)
        l=1
        r=max(arr)
        while l<r:
            mid=l+(r-l)//2;
            tmp=0
            for val in arr:
                if val>mid:
                    tmp+=mid
                else:
                    tmp+=val
                    
            if tmp<target:
                l=mid+1
            else:
                r=mid
                
                
        sum1=0
        sum2=0
        for val in arr:
            if val>l:
                sum1+=l
            else:
                sum1+=val
            
            if val>l-1:
                sum2+=l-1
            else:
                sum2+=val
                
        if abs(sum2-target)<= abs(sum1-target):
            return l-1
        else:
            return l

t=int(input())
while t:
   n,target=map(int,input().split())
   list1=list(map(int,input().split()))
   print(findBestValue(list1,target))
   t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not?