Python3 solution using prefix sum and binary search
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\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def minOperations(self, nums: List[int], queries: List[int]) -> List[int]:\n        nums.sort()\n        prefix_sum = []\n        su = 0\n        for i in nums:\n            su += i\n            prefix_sum.append(su)\n        res = []\n        for cur in queries:\n            ind = self.binary_search(cur, nums)\n            if nums[ind] > cur:\n                before = 0\n                ind -= 1\n            else:\n                before = prefix_sum[ind]\n            after = prefix_sum[-1] - before\n            before_dis = cur * (ind + 1) - before\n            after_dis = after - cur * (len(nums) - ind - 1)\n            res.append(before_dis + after_dis)\n        return res\n    \n    def binary_search(self, cur: int, nums: List[int]) -> int:\n        start = 0\n        end = len(nums) - 1\n        while start + 1 < end:\n            mid = start + (end - start) // 2\n            if nums[mid] == cur:\n               return mid\n            elif nums[mid] > cur:\n                end = mid\n            else:\n                start = mid\n        if nums[end] < cur:\n            return end\n        return start\n```
['Python3']