mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你一个长度为 <code>n</code> 的整数数组 <code>nums</code> ,和一个长度为 <code>m</code> 的整数数组 <code>queries</code> 。</p>
 | 
						||
 | 
						||
<p>返回一个长度为 <code>m</code> 的数组<em> </em><code>answer</code><em> </em>,其中<em> </em><code>answer[i]</code><em> </em>是 <code>nums</code> 中<span style=""> </span>元素之和小于等于 <code>queries[i]</code> 的 <strong>子序列</strong> 的 <strong>最大</strong> 长度<span style=""> </span><span style=""> </span>。</p>
 | 
						||
 | 
						||
<p><strong>子序列</strong> 是由一个数组删除某些元素(也可以不删除)但不改变剩余元素顺序得到的一个数组。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>nums = [4,5,2,1], queries = [3,10,21]
 | 
						||
<strong>输出:</strong>[2,3,4]
 | 
						||
<strong>解释:</strong>queries 对应的 answer 如下:
 | 
						||
- 子序列 [2,1] 的和小于或等于 3 。可以证明满足题目要求的子序列的最大长度是 2 ,所以 answer[0] = 2 。
 | 
						||
- 子序列 [4,5,1] 的和小于或等于 10 。可以证明满足题目要求的子序列的最大长度是 3 ,所以 answer[1] = 3 。
 | 
						||
- 子序列 [4,5,2,1] 的和小于或等于 21 。可以证明满足题目要求的子序列的最大长度是 4 ,所以 answer[2] = 4 。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>nums = [2,3,4,5], queries = [1]
 | 
						||
<strong>输出:</strong>[0]
 | 
						||
<strong>解释:</strong>空子序列是唯一一个满足元素和小于或等于 1 的子序列,所以 answer[0] = 0 。</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>n == nums.length</code></li>
 | 
						||
	<li><code>m == queries.length</code></li>
 | 
						||
	<li><code>1 <= n, m <= 1000</code></li>
 | 
						||
	<li><code>1 <= nums[i], queries[i] <= 10<sup>6</sup></code></li>
 | 
						||
</ul>
 |