Easy solution in python-3
Intuition\nIt can be solved using naive approach in O(n^2) time complexity, which includes one outer for loop for iterating in queries list and the inner outer 
# Intuition\nIt can be solved using naive approach in O(n^2) time complexity, which includes one outer for loop for iterating in queries list and the inner outer loop for calculating the sum (as shown) in \'nums\' list. Since, this solution is not optimal, we have to reduce the time complexity further.\n# Naive approach:\n    def minOperations(self, nums: List[int], queries: List[int]) -> List[int]:\n        ans=[]\n        for i in range(len(queries)):\n            summ=0\n            for j in range(0,len(nums)):\n                summ+=abs(nums[j]-queries[i])\n            ans.append(summ)\n        return(ans)\n\n# Approach\nTo reduce the T.C, the other possible methods for getting the summ varibale should be either O(log(n)) or O(1). Since we know that, if we make a prefix sum array, we can retrieve sum in O(1) only, we have used that here.\nThe reason for using binary search here is: If we can get the index of a number (say i), we can get the sum of elements upto the \'i\'th index using prefix_sum array(that too in O(1) time).\n# Complexity\n- Time complexity:\nO(nlog(n))\n\n- Space complexity:\nO(n) for the extra array that i took (arr)\n\n# Code\n```\nclass Solution:\n    def minOperations(self, nums: List[int], queries: List[int]) -> List[int]:\n        n=len(nums)\n        nums.sort()\n        arr=nums.copy()\n        for i in range(1,len(nums)):  #Prefix_sum\n            nums[i]+=nums[i-1]\n        \n\n        def binary_search(nums,x):\n            start=0\n            end=len(nums)-1 \n            while(start<=end):\n                mid=(start+end)//2\n                if(nums[mid]==x):\n                    return(mid)\n                elif(nums[mid]>x):\n                    end=mid-1\n                else:\n                    start=mid+1 \n            return(start)\n        \n\n        ans=[]\n        for i in range(0,len(queries)):\n            summ=0\n            index=binary_search(arr,queries[i])  #to get the index\n            if(index==0):\n                summ=nums[-1]-(n*queries[i])\n            else:\n                summ=(index*queries[i])-(nums[index-1])    #for summ of elements before index\n                summ+=(nums[-1]-nums[index-1])-((n-index)*queries[i])     #for summ of elements after index\n            ans.append(summ)\n        return(ans)\n```
['Binary Search', 'Sorting', 'Prefix Sum', 'Python3']