/*
* @lc app=leetcode.cn id=1403 lang=typescript
*
* [1403] 非递增顺序的最小子序列
*/
// @lc code=start
function minSubsequence(nums: number[]): number[] {}
// @lc code=end
function minSubsequence(nums: number[]): number[] {
nums.sort((a, b) => b - a)
const sum = nums.reduce((a, b) => a + b, 0)
let res = 0
for (let i = 0; i < nums.length; i++) {
res += nums[i]
if (res > sum / 2) {
return nums.slice(0, i + 1)
}
}
return []
}
test.each([
{ input: { nums: [4, 3, 10, 9, 8] }, output: [10, 9] },
{ input: { nums: [4, 4, 7, 6, 7] }, output: [7, 7, 6] },
])('input: nums = $input.nums', ({ input: { nums }, output }) => {
expect(minSubsequence(nums)).toEqual(output)
})