Java solution
Code


# Code
```java []
class Solution {
    public int binarySearch(int[] nums, int k){
        int left = 0, right = nums.length;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] < k) left = mid + 1;
            else right = mid;
        }
        return left;
    }

    public List<Long> minOperations(int[] nums, int[] queries) {

        //Initializations
        int n = nums.length;
        List<Long> result = new ArrayList<>();

        //sort numbers
        Arrays.sort(nums);

        //Calculate prefix sum
        long[] prefixSum = new long[nums.length];
        prefixSum[0] = nums[0];
        for(int i = 1 ; i < nums.length ; i++){
            prefixSum[i] = prefixSum[i-1] + nums[i];
        }

        //Apply binary search for each query to get the mid index
        for(int query : queries){
            long sum = 0;
            int index = binarySearch(nums, query);
            if(index > 0){
                sum += (long) query * index - prefixSum[index - 1];
            }
            if(index < n){
                sum += (prefixSum[n - 1] - (index == 0 ? 0 : prefixSum[index - 1])) - (long) query * (n - index);
            } 
            result.add(sum);
        }

        return result;
    }
}
```
['Java']