Explained - Prefix sum & Lowerbound || Very simple & Easy to Understand Solution
Approach\n\n1. Evaluate prefix sum array\n2. find the index of lower bound of the query q\n3. Once we found the index, the lower half evaluation would take \n  
# Approach\n\n1. Evaluate prefix sum array\n2. find the index of lower bound of the query q\n3. Once we found the index, the lower half evaluation would take \n        (ind * q - v[ind-1]) operations.\n4. Upper half array can be evaluated as equal which take \n        (v.back() - v[ind-1]) - ( nums.size() - ind )*q;\n..............^ cur sum....................^sum when all equal\n# Code\n```\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        sort(nums.begin(), nums.end());\n        vector<long long> ans, v;\n        v.push_back(nums[0]);\n        for(int i = 1; i < nums.size(); ++i) v.push_back(v.back() + (long long)nums[i]);\n        for(auto q: queries){\n            long long ind = (lower_bound(nums.begin(), nums.end(), q) - nums.begin());\n            long long opLow= ind*(long long)q - ((ind > 0)?v[ind-1]:0); \n            long long opHigh = (v.back() - ((ind > 0)?v[ind-1]:0 ) ) - ( (long long)nums.size() - ind )*(long long)q; \n            ans.push_back(opLow + opHigh);\n        }\n        return ans;\n    }\n};\n```
['C++']