Prefix sum  + Binary search. 6 lines
python3 []\nclass Solution:\n    def minOperations(self, nums: List[int], queries: List[int]) -> List[int]:\n        nums.sort()\n        pref = [*accumulate(nu
```python3 []\nclass Solution:\n    def minOperations(self, nums: List[int], queries: List[int]) -> List[int]:\n        nums.sort()\n        pref = [*accumulate(nums, initial = 0)]\n        ans, n = [], len(nums)\n        for q in queries:\n            i = bisect_left(nums, q)\n            ans.append((q*i - pref[i])*2 + pref[-1] - q*n)  #(q*i - pref[i]) + (pref[-1]-pref[i] - q*(n-i))\n        return ans\n```
['Binary Search', 'Prefix Sum', 'Python3']