PREFIX & SUFFIX SUM || BINARY SEARCH || C++
\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        vector<long long int> v;\n        sort(nums
````\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        vector<long long int> v;\n        sort(nums.begin(),nums.end());\n        vector<long long int> l(nums.size()),r(nums.size());\n        l[0] = nums[0];\n        r[nums.size()-1] = nums[nums.size()-1];\n        for(int i = 1; i < nums.size(); i++){\n            l[i] += nums[i]+l[i-1];\n        }\n        for(int i = nums.size()-2; i>=0; i--){\n            r[i] += nums[i]+r[i+1];\n        }\n        for(int i = 0; i < queries.size(); i++){\n            int a = 0, b = nums.size()-1, mid,k=nums.size();\n            while(a<=b){\n                mid = (b-a)/2+a;\n                if(nums[mid]>=queries[i]){\n                    k = mid;\n                    b = mid-1;\n                }else{\n                    a= mid+1;\n                }\n            }\n            long long int aa = 0;\n            if(k-1>=0){\n                aa += k*1LL*queries[i]-l[k-1];\n            }if(k<nums.size()){\n                aa += r[k]-(nums.size()-k)*1LL*queries[i];\n            }\n            v.push_back(aa);\n        }\n        return v;\n    }\n};\n````
['Binary Search', 'C', 'Sorting', 'Binary Tree', 'Prefix Sum', 'C++']