Beats 90% of Coders || Best Solution || Pre Sum technique used
Code
# Code
```cpp []
class Solution {
public:
    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {
        sort(nums.begin(), nums.end());
        int n = nums.size();
        vector<long long> preSum(n+1, 0);

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


        vector<long long> ans;

        for(int q: queries) {
            int idx = lower_bound(nums.begin(), nums.end(), q) - nums.begin();

            long long leftSum = preSum[idx];
            long long rightSum = preSum[n] - preSum[idx];

            long long leftOp = (1LL * idx * q) - leftSum;
            long long rightOp = rightSum - (1LL * (n-idx) * q);

            ans.push_back(leftOp + rightOp);
        }

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