Prefix Sum
The minimal sum of any k elements of the array is the sum of k smallest elements.\n\nSo, we sort the array first. Then, we apply prefix sum so that the array i-
The minimal sum of any `k` elements of the array is the sum of `k` smallest elements.\n\nSo, we sort the array first. Then, we apply prefix sum so that the array `i`-th element of the array contains the minimal sum of `i` elements.\n\nFinally, we use a binary search to find the maximum number of elements for each query.\n\n**Python 3**\n```python\nclass Solution:\n    def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]:\n        nums = list(accumulate(sorted(nums)))\n        return [bisect_right(nums, q) for q in queries]\n```\n\n**Java**\n```java\npublic int[] answerQueries(int[] nums, int[] queries) {\n    Arrays.sort(nums);\n    Arrays.parallelPrefix(nums, Integer::sum);\n    for (int i = 0; i < queries.length; ++i) {\n        int pos = Arrays.binarySearch(nums, queries[i] + 1);\n        queries[i] = pos < 0 ? ~pos : pos;\n    }\n    return queries;\n}\n```\n**C++**\n```cpp\nvector<int> answerQueries(vector<int>& nums, vector<int>& queries) {\n    sort(begin(nums), end(nums));\n    partial_sum(begin(nums), end(nums), begin(nums));\n    transform(begin(queries), end(queries), begin(queries), [&](int q){ \n        return upper_bound(begin(nums), end(nums),  q) - begin(nums);\n    });\n    return queries;\n}\n```
['C', 'Java', 'Python3']