Python 3   ||   1-6 lines,  w/ example   ||   T/S: 97% / 95%
Here\'s the plan:\n- First, we sort nums.\n\n- Second, we condstruct a prefix array for nums. The ith element of pref is the sum of the first i + 1 elements of 
Here\'s the plan:\n- First, we sort `nums`.\n\n- Second, we condstruct a prefix array for nums. The *i*th element of `pref` is the sum of the first *i* + 1 elements of the sorted `nums`.\n- Third, we use `bisect.bisect_right` to determine the cut for satisfying each query. These cuts are appended to `ans`. \n\n```\nclass Solution:\n    def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]:\n\n        nums.sort()                          #   Example: nums = [4,5,2, 1] queries = [3,10,21]\n                                             # After sorting:    [1,2,4, 5]\n        pref = list(accumulate(nums))        #            pref = [1,3,7,12]\n\n                                             #   q                  maxseq      ans\n        ans = []                             #  \u2013\u2013\u2013                 \u2013\u2013\u2013\u2013\u2013\u2013   \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\n        for q in queries:                    #   3   [1,3/\\7, 12]      2       [2]\n            maxseq = bisect_right(pref, q)   #  10   [1,3, 7/\\12]      3       [2,3]                  3\n            ans.append(maxseq)               #  21   [1,3,7,12/\\]      4       [2,3,5]\n\n```\n[https://leetcode.com/problems/longest-subsequence-with-limited-sum/submissions/1287497037/](https://leetcode.com/problems/longest-subsequence-with-limited-sum/submissions/1287497037/)\n\n\nI could be wrong, but I think that time complexity is *O*(O(N log N + Q log N)) and space complexity is *O*(*N*), in which *N* ~ `len(nums)` and *Q* ~ `len(queries)`\n\nHere\'s the one-liner:\n```\nclass Solution:\n    def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]:\n        return [bisect_right(list(accumulate(sorted(nums))), q) for q in queries\n```
['Python3']