Prefix Sum + Binary Search || C++ Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    Time Complexity : O(Nlog(N))\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    Space Complexity : O(N);\n\n# Code\n```\nstatic auto fastio = []() {\n    std::ios_base::sync_with_stdio(false);\n    std::cin.tie(nullptr);\n    std::cout.tie(nullptr);\n};\n\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        fastio();\n        int n = nums.size();\n        int m = queries.size();\n        sort(nums.begin(), nums.end());\n        vector<long long> prefix_sum;\n        prefix_sum.push_back(nums[0]);\n        for (int i = 1; i < n; i++) {\n            prefix_sum.push_back(prefix_sum.back() + nums[i]);\n        }\n        vector<long long> result;\n        for (int i = 0; i < m; i++) {\n            long long val = queries[i];\n            int val_lb =\n                lower_bound(nums.begin(), nums.end(), val) - nums.begin();\n            long long sum, req;\n            if (val_lb == n) {\n                sum = prefix_sum[val_lb - 1];\n                req = val * n;\n                result.push_back(req - sum);\n            } else if (val_lb == 0) {\n                (sum, req) = {0};\n                // cout << sum << " " << req << endl;\n                if (nums[val_lb] == queries[i]) {\n                    sum = prefix_sum[n - 1] - prefix_sum[0];\n                    req = val * (n - 1);\n                } else {\n                    sum = prefix_sum[n - 1];\n                    req = val * (n);\n                }\n                result.push_back(sum - req);\n            } else {\n                if (nums[val_lb] == queries[i]) {\n                    if (val_lb == n - 1) {\n                        sum = prefix_sum[val_lb - 1];\n                        req = val * (n - 1);\n                        result.push_back(req - sum);\n                    } else {\n                        sum = (val * (val_lb)) - prefix_sum[val_lb - 1];\n                        sum += prefix_sum[n - 1] - prefix_sum[val_lb] -\n                               (val * (n - 1 - val_lb));\n                        result.push_back(sum);\n                    }\n                } else {\n                    sum = (val * (val_lb)) - prefix_sum[val_lb - 1];\n                    sum += (prefix_sum[n - 1] - prefix_sum[val_lb - 1]) -\n                           (val * (n - val_lb));\n                    result.push_back(sum);\n                }\n            }\n        }\n        return result;\n    }\n};\n```
['Binary Search', 'Sorting', 'Prefix Sum', 'C++']