NLogN | Easy Solution
For each query target in queries, the solution performs binary search on the sorted array nums to find the index i such that nums[i] is the smallest element gre
For each query target in queries, the solution performs binary search on the sorted array nums to find the index i such that nums[i] is the smallest element greater than or equal to the target. It then calculates the sum of the following two parts:\n\nThe total number of operations required to make the first i elements of nums equal to target. This is calculated as i * target - prefix[i-1] where prefix[i-1] represents the sum of the first i-1 elements of nums.\n\nThe total number of operations required to make the last n-i elements of nums equal to target. This is calculated as (prefix[n-1] - prefix[i-1]) - (n - i) * target where prefix[n-1] - prefix[i-1] represents the sum of the last n-i elements of nums.\n        \n\n# Code\n```\nclass Solution:\n    def minOperations(self, nums: List[int], queries: List[int]) -> List[int]:\n        prefix = []\n        nums.sort()\n        prev = 0\n        for num in nums:\n            prev += num\n            prefix.append(prev)\n        \n        data = []\n        for target in queries:\n            i = 0\n            k = len(prefix)\n            tot = 0\n            while i < k:\n                j = (i + k) // 2\n                if nums[j] > target: k = j\n                else: i = j + 1\n        \n            backs = prefix[i - 1] if i != 0 else 0\n            tot += i * target - backs\n            tot += (prefix[-1] - backs) - (len(nums) - i) * target\n            data.append(tot)\n        \n        return data\n```
['Python3']