# LeetCode contest 183 5376. 非递增顺序的最小子序列 Minimum Subsequence in Non-Increasing Order

### 一、中文版

1 <= nums.length <= 500

1 <= nums[i] <= 100

### 二、英文版

Given the array nums, obtain a subsequence of the array whose sum of elements is strictly greater than the sum of the non included elements in such subsequence.
If there are multiple solutions, return the subsequence with minimum size and if there still exist multiple solutions, return the subsequence with the maximum total sum of all its elements. A subsequence of an array can be obtained by erasing some (possibly zero) elements from the array.
Note that the solution with the given constraints is guaranteed to be unique. Also return the answer sorted in non-increasing order.
Example 1:
Input: nums = [4,3,10,9,8]
Output: [10,9]
Explanation: The subsequences [10,9] and [10,8] are minimal such that the sum of their elements is strictly greater than the sum of elements not included, however, the subsequence [10,9] has the maximum total sum of its elements.
Example 2:
Input: nums = [4,4,7,6,7]
Output: [7,7,6]
Explanation: The subsequence [7,7] has the sum of its elements equal to 14 which is not strictly greater than the sum of elements not included (14 = 4 + 4 + 6). Therefore, the subsequence [7,6,7] is the minimal satisfying the conditions. Note the subsequence has to returned in non-decreasing order.
Example 3:
Input: nums = [6]
Output: [6]
Constraints:
1 <= nums.length <= 500
1 <= nums[i] <= 100

class Solution:
def minSubsequence(self, nums: List[int]) -> List[int]:
nums.sort(reverse=True)
sum1, sum2 = 0, 0
res = []
for i in range(len(nums)):
sum2 += nums[i]
for i in range(len(nums)):
sum1 += nums[i]
res.append(nums[i])
sum2 -= nums[i]
if sum1 > sum2:
return res

### 四、解题报告

1、如果存在多个解决方案，只需返回 长度最小 的子序列。如果仍然有多个解决方案，则返回 元素之和最大 的子序列

2、返回的答案应当按 非递增顺序 排列

sum1 表示前半部分的和，sum2 表示后半部分的和（初值为数组中所有数字之和），随着 i 后移，sum1 不断增大，sum2 不断减少，当出现第一个 sum1 > sum2 时，即为所求（贪心思想）。

|
6天前
|

6 1
|
7天前
|

10 1
|
7天前
|

LeetCode题目115:不同子序列
LeetCode题目115:不同子序列
9 1
|
12天前
|
Java

15 1
|
12天前
|

【经典算法】LeetCode 392 判断子序列(Java/C/Python3/Go实现含注释说明,Easy)
【经典算法】LeetCode 392 判断子序列(Java/C/Python3/Go实现含注释说明,Easy)
14 0
|
1月前
leetcode代码记录（最长连续递增序列
leetcode代码记录（最长连续递增序列
17 2
|
1月前
leetcode代码记录（最长递增子序列
leetcode代码记录（最长递增子序列
14 1
|
1月前
|

leetcode代码记录（摆动序列
leetcode代码记录（摆动序列
17 0
|
1月前
|

37 1
|
3天前
|

【数据结构与算法】：关于时间复杂度与空间复杂度的计算（C/C++篇）——含Leetcode刷题-2
【数据结构与算法】：关于时间复杂度与空间复杂度的计算（C/C++篇）——含Leetcode刷题
12 2