[LeetCode] Maximize Points After Choosing K Tasks

3767. Maximize Points After Choosing K Tasks

You are given two integer arrays, technique1 and technique2, each of length n, where n represents the number of tasks to complete.

  • If the i^th task is completed using technique 1, you earn technique1[i] points.
  • If it is completed using technique 2, you earn technique2[i] points.

You are also given an integer k, representing the minimum number of tasks that must be completed using technique 1.

You must complete at least k tasks using technique 1 (they do not need to be the first k tasks).

The remaining tasks may be completed using either technique.

Return an integer denoting the maximum total points you can earn.

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public:
long long maxPoints(vector<int>& reward1, vector<int>& reward2, int k) {
long long res = accumulate(begin(reward1), end(reward1), 0ll);
vector<long long> D;
for(long long i = 0; i < reward1.size(); i++) D.push_back(reward2[i] - reward1[i]);
sort(begin(D), end(D));
while(D.size() > k and D.back() > 0 ) {
res += D.back(); D.pop_back();
}
return res;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/04/PS/LeetCode/maximize-points-after-choosing-k-tasks/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.