Prefix & Suffix + Binary Search | C++
\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        long long n = nums.size();\n        sort(nu
```\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        long long n = nums.size();\n        sort(nums.begin(), nums.end());\n        vector<long long> ps(n + 1), ss(n + 1), ans;\n        for(int i=1; i<=n; i++) ps[i]  = ps[i - 1] + nums[i  - 1];\n        for(int i=n-1; i>=0; i--) ss[i] = ss[i + 1] + nums[i];\n        \n        for(int q : queries) {\n            long long pos = lower_bound(nums.begin(), nums.end(), q) - nums.begin();\n            long long val = pos * q  - ps[pos] + ss[pos] - (n - pos) * q;\n            ans.push_back(val);\n        }\n        return ans;\n    }\n};\n```
['Binary Search', 'Suffix Array', 'Sorting', 'Prefix Sum', 'C++']