原题链接:1403. 非递增顺序的最小子序列
solution:
class Solution {
public:
vector<int> minSubsequence(vector<int>& nums) {
sort(nums.begin(), nums.end());
int sum = 0;
for(auto &x : nums) sum += x;
vector<int> res; //返回值
int s = 0,j = nums.size() - 1;
while(j >= 0 && s <= sum / 2) {
res.push_back(nums[j]);
s += nums[j--];
}
return res;
}
};