Python3 One Line (beats 98.93%; explained)
Intuition\nSince we are looking for a subsequence (i.e. we can delete any elements from the original list) we can just take the smallest elements for each query
# Intuition\nSince we are looking for a subsequence (i.e. we can delete $$any$$ elements from the original list) we can just take the smallest elements for each query. By the given definition of a subsequence, however many elements are needed (say $$m$$ elements) we could simply delete the others in the original list, wherever they happen to be, to get the list of the $$m$$ smallest.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIn preparation for each query, sort the list and record the sums after adding each element from the sorted list, like so:\n```acc := list(accumulate(sorted(nums)))```\n\nThen each query is just a matter of finding where one would insert a number (```q```) in a sorted list (```acc```). We accomplish this with each query by using the ```bisect``` library, like so:\n```bisect.bisect_right(acc, q)```\n\nNote: We use ```bisect_right``` to get the maximum element count that satisfies the "less than or equal" requirement on the sum.\n\nTo fit it all in one line, use two tricks:\n1. Use the walrus operator to assign the running sum to the variable ```acc```. Then, to avoid showing that list in the final output, take no elements from it (e.g. ```someList[:0]``` means take an empty subset of the list ```someList```) like so:\n```(acc := list(accumulate(sorted(nums))))[:0]```\n2. Then, use a list interpretation to run the queries and generate a list of results, like so:\n```[bisect.bisect_right(acc, q) for q in queries]```\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nWhere $$n$$ is the length of the array ```nums```, to generate the running sum requires $$O(n)$$ time. Then, placing all of the $$m$$ query values in that running sum by using ```bisect``` takes $$O(m.log.n)$$ time (that is, $$O(log.n)$$ insertion for each of $$m$$ elements).\n\nOverall, the time complexity depends on whether $$n$$ or $$m$$ is larger (it could be driven either by generating the running sum or by the number of queries run later) so it is $$O(n + m.log.n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nUnfortunately, for the sake of brevity, this approach requires $$O(n)$$ extra space. With a couple more lines, one could use constant extra space, but in this day and age, who has time to write more than one line?\n\nOverall, the space complexity is $$O(n)$$\n\n# Here is Some Code:\n```\n#Runtime: 96 ms, faster than 98.93% of Python3 online submissions for Longest Subsequence With Limited Sum.\n#Memory Usage: 14.2 MB, less than 40.29% of Python3 online submissions for Longest Subsequence With Limited Sum.\nclass Solution:\n    def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]:\n        return (acc := list(accumulate(sorted(nums))))[:0] + [bisect.bisect_right(acc, q) for q in queries]\n```
['Python3']