Maximize Points After Choosing K Tasks

You are given two integer arrays, technique1 and technique2, both of length n. This length represents the total number of tasks you need to complete.

For each task i:

  • If you complete it using technique 1, you earn technique1[i] points.
  • If you complete it using technique 2, you earn technique2[i] points.

You are also given an integer k. You must complete at least k tasks using technique 1. The remaining tasks can be completed using either technique.

Return the maximum possible total points you can earn.

Example 1:

Input: technique1 = [4, 4, 4], technique2 = [1, 2, 3], k = 1

Output: 12

Explanation:

We must complete at least 1 task using technique 1. Since technique 1 yields strictly more points for every task (4 > 1, 4 > 2, 4 > 3), we should just complete all 3 tasks using technique 1 to maximize our score. Total points = 4 + 4 + 4 = 12.

Example 2:

Input: technique1 = [1, 1, 1], technique2 = [5, 5, 5], k = 2

Output: 7

Explanation:

Technique 2 is vastly superior. However, our quota forces us to take a loss and pick at least 2 tasks using technique 1. We take the 1 point for the first two tasks, and then gladly use technique 2 for the final task. Total points = 1 + 1 + 5 = 7.

Now Your Turn!

Pick the correct output for the given input

Input: technique1 = [10, 10], technique2 = [20, 20], k = 0

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= n == technique1.length == technique2.length <= 105
  • 1 <= technique1[i], technique2[i] <= 105
  • 0 <= k <= n

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
long long maximizePoints(vector<int>& technique1, vector<int>& technique2, int k) {
}
};
Test Case

Input:

K
Technique1
Technique2