Python brute to better
O(NLogN)+O(QN)\n\ndef answerQueries(self, nums: List[int], queries: List[int]) -> List[int]:\n        nums.sort()\n        res = []\n        \n        for query
### O(NLogN)+O(Q*N)\n```\ndef answerQueries(self, nums: List[int], queries: List[int]) -> List[int]:\n        nums.sort()\n        res = []\n        \n        for query in queries:\n            i = 0\n            currentSum = 0\n            while i<len(nums):\n                if currentSum+nums[i] > query: break \n                currentSum+=nums[i]\n                i+=1\n            res.append(i)\n        return res\n```\n           \n### O(NLOGN) + O(Q*logN) -> prefixsum and binary search\n```\ndef answerQueries(self, nums: List[int], queries: List[int]) -> List[int]:\n        nums.sort()\n        n = len(nums)\n        \n        prefixSum = [0]*n\n        prefixSum[0] = nums[0]\n        res = []\n        \n        for i in range(1,n):\n            prefixSum[i] = nums[i]+prefixSum[i-1]     \n        \n        for query in queries:\n            i, j = 0, n   \n            while i<j:\n                mid = i+(j-i)//2 \n                if prefixSum[mid] > query:\n                    j = mid\n                else:\n                    i = mid+1\n            res.append(i)\n        return res\n```\n
['Binary Search', 'Prefix Sum', 'Python']