Easy
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) {
        vector<long long> ans;
        int n=nums.size();
        sort(nums.begin(),nums.end());
        vector<long long> prefixSum(n+1,0);
        for(int i=1;i<=n;i++){
            prefixSum[i]=prefixSum[i-1]+nums[i-1];
        }
        for(auto it:queries){
            auto idx=upper_bound(nums.begin(),nums.end(),it)-nums.begin();
            long long left=idx*it-prefixSum[idx];
            long long right=(prefixSum[n]-prefixSum[idx])-(n-idx)*it;
            ans.push_back(left+right);
        }
        return ans;
    }
};
```
['C++']