prefix sum and binary search
Intuitionsort the nums, then do prefix sum.find the position of each query, the left part would be query * number of left - sum of left, the right part would be
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
sort the nums, then do prefix sum. 
find the position of each query, the left part would be query * number of left - sum of left, the right part would be sum of right - query * number of right 
# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(nlog(n)) + O(m * log(n))
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(n + 1)
# Code
```cpp []
class Solution {
public:
    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {
        sort(nums.begin(), nums.end());
        const int m = nums.size();
        vector<long long> sum(m + 1);
        for (int i = 0; i < m; ++ i)
            sum[i + 1] = sum[i] + nums[i]; 
        const int n = queries.size();
        vector<long long> res(n);
        for (int i = 0; i < n; ++ i)
        {
            const auto it = upper_bound(nums.cbegin(), nums.cend(), queries[i]);
            const int index = distance(nums.cbegin(), it) + 1;
            const long long left = static_cast<long long>(queries[i]) * (index - 1) - sum[index - 1];
            const long long right = sum.back() - sum[index - 1] - static_cast<long long>(queries[i]) * (m - index + 1);
            res[i] = left + right;
        }
        return res;
    }
};
```
['C++']