solution using prefix sum
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```cpp []
class Solution {
public:
    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {
        int n = nums.size();
        vector<long long> ans;
        vector<long long> preSum(n+1);
        
        sort(nums.begin(), nums.end());

        preSum[0] = nums[0];
        for(int i= 1; i<n; i++){
            preSum[i] = preSum[i-1] + nums[i];
        }

        preSum.insert(preSum.begin(), 0);

        for(long long q : queries){
            auto iter = upper_bound(nums.begin(), nums.end(), q);
            int index = iter - nums.begin();
            //cout<<"index=>"<<index<<endl;

            long long left = index*q - preSum[index];
            long long right = preSum[n] - preSum[index] - (n-index)*q;
            //cout<<"n=>"<<n<<" preSum[n]=>"<<preSum[n]<<" preSum[index]=>"<<preSum[index]<<endl;
            //cout<<"left=>"<<left<<" right=>"<<right<<endl;
            ans.push_back(left+right);
        }

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