1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-09 09:21:40 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/受标签影响的最大值 [largest-values-from-labels].html
2025-01-09 20:29:41 +08:00

60 lines
2.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>以两个整数数组 &nbsp;<code>values</code>&nbsp;<code>labels</code>&nbsp;给定&nbsp;<code>n</code>&nbsp;个项的值和标签,并且给出两个整数&nbsp;<code>numWanted</code>&nbsp;<code>useLimit</code></p>
<p>你的任务是从这些项中找到一个值的和 <strong>最大</strong> 的子集使得:</p>
<ul>
<li>项的数量 <strong>最多</strong>&nbsp;<code>numWanted</code></li>
<li>相同标签的项的数量&nbsp;<strong>最多 </strong>&nbsp;<code>useLimit</code></li>
</ul>
<p>返回最大的和。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">values = [5,4,3,2,1], labels = [1,1,2,2,3], numWanted = 3, useLimit = 1</span></p>
<p><strong>输出:</strong><span class="example-io">9</span></p>
<p><strong>解释:</strong></p>
<p>选择的子集是第一个、第三个和第五个项,其值之和为 5 + 3 + 1。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">values = [5,4,3,2,1], labels = [1,3,3,3,2], numWanted = 3, useLimit = 2</span></p>
<p><strong>输出:</strong><span class="example-io">12</span></p>
<p><strong>解释:</strong></p>
<p>选择的子集是第一个、第二个和第三个项,其值之和为 5 + 4 + 3。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">values = [9,8,8,7,6], labels = [0,0,0,1,1], numWanted = 3, useLimit = 1</span></p>
<p><strong>输出:</strong><span class="example-io">16</span></p>
<p><strong>解释:</strong></p>
<p>选择的子集是第一个和第四个项,其值之和为 9 + 7。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == values.length == labels.length</code></li>
<li><code>1 &lt;= n &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>0 &lt;= values[i], labels[i] &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= numWanted, useLimit &lt;= n</code></li>
</ul>