easy line by line cpp code
\n# Code\ncpp []\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        sort(begin(nums), end(nums)
\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        sort(begin(nums), end(nums));  // Sort nums\n        int n = nums.size();\n\n        // Create prefix sum array\n        vector<long long> ps(n, 0);\n        ps[0] = nums[0];\n        for (int i = 1; i < n; i++) {\n            ps[i] = ps[i - 1] + nums[i];\n        }\n\n        vector<long long> ans;\n        for (int x : queries) {\n            int idx = lower_bound(nums.begin(), nums.end(), x) - nums.begin();\n            \n            // Case when idx == 0 (all elements are greater than x)\n            long long leftSum = (idx > 0) ? ps[idx - 1] : 0;\n            long long rightSum = ps[n - 1] - leftSum;\n\n            long long leftOps = (idx > 0) ? (1LL * x * idx - leftSum) : 0;\n            long long rightOps = (idx < n) ? (rightSum - 1LL * x * (n - idx)) : 0;\n\n            ans.push_back(leftOps + rightOps);\n        }\n\n        return ans;\n    }\n};\n\n```
['Binary Search', 'Prefix Sum', 'C++']