力扣2389.和有限的最长子序列
-
排序 + 前缀和二分
cpp
class Solution {
public:
vector<int> answerQueries(vector<int>& nums, vector<int>& queries) {
sort(nums.begin(),nums.end());
for(int i=1;i<nums.size();i++)
nums[i] += nums[i-1];
for(int &x:queries)
{
x = ranges::upper_bound(nums,x) - nums.begin();
}
return queries;
}
};