Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitedd6186

Browse files
committed
Added details to 3478-choose-k-elements-with-maximum-sum.md
1 parent1c57b9c commitedd6186

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

‎en/3001-4000/3478-choose-k-elements-with-maximum-sum.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,21 @@ Since all elements in `nums1` are equal, no indices satisfy the condition `nums1
7070

7171
* Seeing this, everyone will definitely think of sorting`nums1` from small to large, so that the front is less than or equal to the back, but the indexes will be**messy** when sorting. If there is no good way to solve this problem, the whole question cannot be solved. Please think about it first.
7272

73-
dddBring the`index` when sorting, that is, the object to be sorted is an array of tuples of`(num, index)`. This technique**must be mastered**, as it will be used in many questions.ddd
73+
<details><summary>Click to view the answer</summary><p>Bring the `index` when sorting, that is, the object to be sorted is an array of tuples of `(num, index)`. This technique **must be mastered**, as it will be used in many questions.</p></details>
7474

7575
After solving the above problems, the indexes are all there, let's continue reading:
7676

7777
* Requirement 2: Choose at most`k` values of`nums2[j]` at these indices to**maximize** the total sum.
7878

7979
After seeing this, have you thought of any good method?
8080

81-
dddHeap sort, maintain a large root heap of size`k`. This is also a knowledge point that is often tested,**must be mastered**.ddd
81+
<details><summary>Click to view the answer</summary><p>Heap sort, maintain a large root heap of size `k`. This is also a knowledge point that is often tested, **must be mastered**.</p></details>
8282

8383
Seeing this, please implement the code according to the above prompts.
8484

8585
* Finally, it is found that the repeated`num` that appear continuously should be specially processed, that is, the values ​​in`answer` corresponding to the same`num` should be the same. There are many ways to deal with it. What is the simplest way to deal with it?
8686

87-
dddUse a`Map`,`key` is`num`, and the same`key` directly uses the`value` corresponding to`key`.ddd
87+
<details><summary>Click to view the answer</summary><p>Use a `Map`, `key` is `num`, and the same `key` directly uses the `value` corresponding to `key`.</p></details>
8888

8989
##Complexity
9090

‎zh/3001-4000/3478-choose-k-elements-with-maximum-sum.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,21 @@
7272
- 要求1:找出所有满足`nums1[j]` 小于`nums1[i]` 的下标`j`
7373
看到这个,大家一定会想到把`nums1` 按从小到大排序,这样,前面的小于等于后面的,但一排序下标就****了。如果对这个问题没有好办法解决,整个题目就做不出来。先请思考下。
7474

75-
ddd在排序时带上索引下标,即排序的对象是元组`(num, index)`的数组。这个技术**一定要掌握**,许多题目都会用到。ddd
75+
<details><summary>点击查看答案</summary><p>在排序时带上索引下标,即排序的对象是元组`(num, index)`的数组。这个技术**一定要掌握**,许多题目都会用到。</p></details>
7676

7777
解决了上面的问题,下标就都有了,我们再看:
7878

7979
- 要求2:从这些下标对应的`nums2[j]` 中选出 至多`k` 个,并**最大化** 这些值的总和作为结果。
8080

8181
看到这个,你想到用什么好方法了吗?
8282

83-
ddd堆排序,维护一个大小为`k` 的大根堆。这也是经常考察的知识点,**一定要掌握**哦。ddd
83+
<details><summary>点击查看答案</summary><p>堆排序,维护一个大小为 `k` 的大根堆。这也是经常考察的知识点,**一定要掌握**哦。</p></details>
8484

8585
看到这,请你先按上文提示把代码实现一下。
8686

8787
- 最后,发现还要对连续出现的重复的`num` 进行特别处理,即相同的`num` 对应的`answer` 中的值应该是一样的。处理方法有多种,怎么处理最简单呢?
8888

89-
ddd用一个`Map``key``num`, 相同的`key` 直接使用`key` 对应的``ddd
89+
<details><summary>点击查看答案</summary><p>用一个 `Map`, `key`为 `num`, 相同的 `key` 直接使用 `key` 对应的`值`。</p></details>
9090

9191
##复杂度
9292

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp