mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-25 23:08:57 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>我们有一个 <code>n</code> 项的集合。给出两个整数数组 <code>values</code> 和 <code>labels</code> ,第 <code>i</code> 个元素的值和标签分别是 <code>values[i]</code> 和 <code>labels[i]</code>。还会给出两个整数 <code>numWanted</code> 和 <code>useLimit</code> 。</p>\n\n<p>从 <code>n</code> 个元素中选择一个子集 <code>s</code> :</p>\n\n<ul>\n\t<li>子集 <code>s</code> 的大小 <strong>小于或等于</strong> <code>numWanted</code> 。</li>\n\t<li><code>s</code> 中 <strong>最多</strong> 有相同标签的 <code>useLimit</code> 项。</li>\n</ul>\n\n<p>一个子集的 <strong>分数 </strong>是该子集的值之和。</p>\n\n<p>返回子集 <code>s</code> 的最大 <strong>分数</strong> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>values = [5,4,3,2,1], labels = [1,1,2,2,3], numWanted = 3, useLimit = 1\n<strong>输出:</strong>9\n<strong>解释:</strong>选出的子集是第一项,第三项和第五项。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>values = [5,4,3,2,1], labels = [1,3,3,3,2], numWanted = 3, useLimit = 2\n<strong>输出:</strong>12\n<strong>解释:</strong>选出的子集是第一项,第二项和第三项。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:</strong>values = [9,8,8,7,6], labels = [0,0,0,1,1], numWanted = 3, useLimit = 1\n<strong>输出:</strong>16\n<strong>解释:</strong>选出的子集是第一项和第四项。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == values.length == labels.length</code></li>\n\t<li><code>1 <= n <= 2 * 10<sup>4</sup></code></li>\n\t<li><code>0 <= values[i], labels[i] <= 2 * 10<sup>4</sup></code></li>\n\t<li><code>1 <= numWanted, useLimit <= n</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 23,
|
||||
"likes": 24,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -161,7 +161,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"4.5K\", \"totalSubmission\": \"8.1K\", \"totalAcceptedRaw\": 4502, \"totalSubmissionRaw\": 8075, \"acRate\": \"55.8%\"}",
|
||||
"stats": "{\"totalAccepted\": \"4.6K\", \"totalSubmission\": \"8.3K\", \"totalAcceptedRaw\": 4622, \"totalSubmissionRaw\": 8306, \"acRate\": \"55.6%\"}",
|
||||
"hints": [
|
||||
"Consider the items in order from largest to smallest value, and greedily take the items if they fall under the use_limit. We can keep track of how many items of each label are used by using a hash table."
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user