Easy Solution using Prefix Sum + lower bound + upper bound
Code\n\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        \n        vector<long long> ans;\n   
# Code\n```\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        \n        vector<long long> ans;\n        int n = nums.size();\n        sort(nums.begin(), nums.end());\n\n        // Ye brute force hai.\n\n        // for(int i = 0; i < queries.size(); i++) {\n        //     long long temp = 0;\n        //     for(int j = 0; j < nums.size(); j++) {\n        //         temp += abs(nums[j] - queries[i]);\n        //     }\n        //     ans.push_back(temp);\n        // }\n\n        // Prefix nikal lo pahle\n        vector<long long> prefix(n+1);\n        prefix[0] = 0;\n        long long sum = 0;\n        for(int i = 0; i < nums.size(); i++) {\n            sum += nums[i];\n            prefix[i+1] = sum;\n        }\n\n        for(auto q: queries) {\n\n            \n            long long lb = lower_bound(nums.begin(), nums.end(), q) - nums.begin() - 1;\n            // lb pe -1 kia hai kyuni ye equal ya usse bada element ka pointer\n            // return karta hai to mujhe usse niche wala chaiye, to agr equal \n            // hua to -1 karu ga aur agr bada hua to -1 karu ga usse niche jane k\n            // liye\n            long long ub = upper_bound(nums.begin(), nums.end(), q) - nums.begin();\n            long long left = 0;\n            if(lb != -1) {\n                left += (q*(lb+1)) - (prefix[lb+1] - prefix[0]);\n            }\n            long long right = 0;\n            if(ub != n) {\n                right += (prefix[n] - prefix[ub]) - (q*(n-ub));\n            }  \n            ans.push_back(left+right);\n        }\n        return ans; \n    }\n};\n```
['Binary Search', 'Prefix Sum', 'C++']