Binary Search + Prefix Sum
\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        \n        int n = size(nums);\n        sort
```\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        \n        int n = size(nums);\n        sort(begin(nums), end(nums));\n        \n        vector<long long> pre(n);\n        \n        pre[0] = nums[0];\n        \n        for(int i = 1; i < n; i++) {\n            pre[i] = 0LL + pre[i-1] + nums[i];\n        }\n        \n        int m = size(queries);\n        vector<long long> res;\n        \n        for(int i = 0; i < m; i++) {\n            long long val = queries[i];\n            \n            int lb = (upper_bound(begin(nums), end(nums),val) - begin(nums));\n            \n            lb--;\n            // cout << lb << \' \';\n            long long ans = 0;\n            if(lb != -1 and lb < n) {\n                long long sum = 1LL * val * (lb+1);\n                ans += 0LL + abs(sum - pre[lb]);\n            }\n            long long rem;\n            if(lb == -1)rem = n;\n            else  rem = n-lb-1;\n            \n            if(rem) {\n                long long sum = 1LL * val * rem;\n                long long sums;\n                if(lb == -1)sums = pre[n-1];\n                else\n                sums = 0LL + pre[n-1] - pre[lb];\n                \n                ans += 0LL + abs(sum - sums);\n            }\n            res.push_back(ans);\n            \n        }\n        \n        return res;\n    }\n};\n```
['Binary Search', 'C', 'Sorting', 'Prefix Sum', 'C++']