3767. Maximize Points After Choosing K Tasks Medium

@problem@discussion
#Array#Greedy#Sorting#Heap (Priority Queue)



1/**
2 * [3767] Maximize Points After Choosing K Tasks
3 *
4 * You are given two integer arrays, technique1 and technique2, each of length n, where n represents the number of tasks to complete.
5 * 
6 * 	If the i^th task is completed using technique 1, you earn technique1[i] points.
7 * 	If it is completed using technique 2, you earn technique2[i] points.
8 * 
9 * You are also given an integer k, representing the minimum number of tasks that must be completed using technique 1.
10 * You must complete at least k tasks using technique 1 (they do not need to be the first k tasks).
11 * The remaining tasks may be completed using either technique.
12 * Return an integer denoting the maximum total points you can earn.
13 *  
14 * <strong class="example">Example 1:
15 * <div class="example-block">
16 * Input: <span class="example-io">technique1 = [5,2,10], technique2 = [10,3,8], k = 2</span>
17 * Output: <span class="example-io">22</span>
18 * Explanation:
19 * We must complete at least k = 2 tasks using technique1.
20 * Choosing technique1[1] and technique1[2] (completed using technique 1), and technique2[0] (completed using technique 2), yields the maximum points: 2 + 10 + 10 = 22.
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io">technique1 = [10,20,30], technique2 = [5,15,25], k = 2</span>
25 * Output: <span class="example-io">60</span>
26 * Explanation:
27 * We must complete at least k = 2 tasks using technique1.
28 * Choosing all tasks using technique 1 yields the maximum points: 10 + 20 + 30 = 60.
29 * </div>
30 * <strong class="example">Example 3:
31 * <div class="example-block">
32 * Input: <span class="example-io">technique1 = [1,2,3], technique2 = [4,5,6], k = 0</span>
33 * Output: <span class="example-io">15</span>
34 * Explanation:
35 * Since k = 0, we are not required to choose any task using technique1.
36 * Choosing all tasks using technique 2 yields the maximum points: 4 + 5 + 6 = 15.
37 * </div>
38 *  
39 * Constraints:
40 * 
41 * 	1 <= n == technique1.length == technique2.length <= 10^5
42 * 	1 <= technique1[i], technique2​​​​​​​[i] <= 10^​​​​​​​5
43 * 	0 <= k <= n
44 * 
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/maximize-points-after-choosing-k-tasks/
49// discuss: https://leetcode.com/problems/maximize-points-after-choosing-k-tasks/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54    pub fn max_points(technique1: Vec<i32>, technique2: Vec<i32>, k: i32) -> i64 {
55        
56    }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn test_3767() {
67    }
68}
69

Back
© 2026 bowen.ge All Rights Reserved.