sorting, prefix sum, binary search Python solution
Intuition\nOnce nums is sorted, we can find a dividing point for each querie using binary search. Then, the left side of nums is less than the querie and the ri
# Intuition\nOnce `nums` is sorted, we can find a dividing point for each querie using binary search. Then, the left side of `nums` is less than the querie and the right side of `nums` is greater than the querie. Using prefix sum hashmap, we can calculate the difference easily.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nsorting, prefix sum, binary search\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: `O(n log n + m log n)`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: `O(n)`\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def minOperations(self, nums: List[int], queries: List[int]) -> List[int]:\n        nums.sort()\n        prefix_hash = {-1: 0} # index: prefix sum\n        presum = 0\n        n = len(nums)\n        for idx, num in enumerate(nums):\n            presum += num\n            prefix_hash[idx] = presum\n        \n        ans = []\n        for q in queries:\n            # print(bisect_left(nums, q))\n            dividing_idx = bisect_left(nums, q)\n            left_side = (q * dividing_idx - prefix_hash[dividing_idx - 1])\n            right_side = (prefix_hash[n-1] - prefix_hash[dividing_idx-1] - q * (n - dividing_idx))\n            ans.append(left_side + right_side)\n\n        return ans\n```
['Python3']