Ugly looking but easy to understand C++ Binary search solution
Code

# Code
```cpp []
class Solution {
public:
    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {

        vector<long long>prefix(nums.size(), 0);
        vector<long long>result;

        sort(nums.begin(), nums.end());

        for (int i = 1; i < nums.size(); i++) {
            prefix[i] = prefix[i - 1] + nums[i - 1];
        }

        for(int i = 0; i < queries.size(); i++) {
            long long num = queries[i];

            auto index = lower_bound(nums.begin(), nums.end(), num);

            int idx = index - nums.begin();

            int size = nums.size();

            if (idx == size) {
                result.push_back((size * num) - prefix[size - 1] - nums[size - 1]);
                continue;
            }

            long long sum_to_left = prefix[idx];

            long long sum_to_right = prefix[size - 1] - prefix[idx] + nums[size - 1];

            cout <<sum_to_left << " "<<sum_to_right<<endl;

            long long rem_left_sum = (num * idx) - sum_to_left;

            long long rem_right_sum = sum_to_right - (num * (nums.size() - idx));

            result.push_back(rem_left_sum + rem_right_sum);
        }

        return result;
        
    }
};
```
['C++']