You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/3001-4000/3478-choose-k-elements-with-maximum-sum.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -70,21 +70,21 @@ Since all elements in `nums1` are equal, no indices satisfy the condition `nums1
70
70
71
71
* 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.
72
72
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>
74
74
75
75
After solving the above problems, the indexes are all there, let's continue reading:
76
76
77
77
* Requirement 2: Choose at most`k` values of`nums2[j]` at these indices to**maximize** the total sum.
78
78
79
79
After seeing this, have you thought of any good method?
80
80
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>
82
82
83
83
Seeing this, please implement the code according to the above prompts.
84
84
85
85
* 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?
86
86
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>