Java prefixSum + binarySearch
IntuitionIf j numbers in nums that are smaller than query[i] then number of increments = query[i] * j - sum of smaller numbersIf k numbers in nums thare are gre
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
If j numbers in nums that are smaller than query[i] then number of increments = query[i] * j - sum of smaller numbers

If k numbers in nums thare are greater than query[i] then number of decrements = sum of larger nums - query[i] * k 

sum of numbers smaller than query of i = prefixSum[i]
sum of numbers larger than queries of i = prefixSum[nums.length] - prefixSum[i]
# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(nlogn + qlogq)

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(n)

# Code
```java []
class Solution {

    public List<Long> minOperations(int[] nums, int[] queries) {
        int n = nums.length;
        Arrays.sort(nums);
        long[] prefixSum = new long[n + 1];

        List<Long> res = new ArrayList<>();
        
        for (int i = 0; i < n; i++) {
            prefixSum[i + 1] = prefixSum[i] + nums[i];
        }

        for (int q = 0; q < queries.length; q++) {
            int targetIndex = binarySearch(nums, queries[q]);

            long leftChanges = (long)queries[q] * targetIndex - prefixSum[targetIndex];

            long rightChanges = (prefixSum[n] - prefixSum[targetIndex]) - (long)queries[q] * (n - targetIndex);

            res.add(rightChanges + leftChanges);

        }

        return res;
    }

    private static int binarySearch(int[] arr, int target) {
        int low = 0, high = arr.length;
        while (low < high) {
            int mid = low + (high - low) / 2;
            if (arr[mid] <= target) {
                low = mid + 1;
            } else {
                high = mid;
            }
        }
        return low;
    }
}
```
['Java']