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: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    long sum=0;
    int j=0;
    long ans=0;
    long res;
    long total=INT_MAX;
    for(int i=0;i<=100000;i++){
        if(i>a[j] && j!=n){sum+=a[j];j++;}
        ans=sum+i*(n-j);
        if(abs(ans-k)<total){res=i;total=abs(ans-k);}
    }
    cout<<res<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not?