There are two sequences of positive integers \(\{a_i\}\) and \(\{b_i\}\), each containing \(n\) elements indexed \(1\) to \(n\). You are to choose \(K\) integers from each sequence, out of which there must be at least \(L\) indices which are chosen in both sequences. Given these requirements, choose these \(2K\) integers such that their sum is maximized.
Formally, you are to choose two sets \(\{c_i\}\) and \(\{d_i\}\) of size K such that
The first line of input consists of a single integer \(T\), the number of testcases.
\(T\) testcases will follow. Each test case consists of 3 lines.
The first line of each testcase will contain 3 integers, \(n\), \(K\), and \(L\).
The second line of each testcase will contain \(n\) integers \(a_1, a_2, \ldots, a_n\).
The third line of each testcase will contain \(n\) integers \(b_1, b_2, \ldots, b_n\).
Output one line for each testcase, each containing a single integer - the maximum sum of elements as described.
Subtask # | Score | Constraints |
---|---|---|
1 | 12 | \(n \leq 10\) |
2 | 8 | \(n \leq 18\) |
3 | 8 | \(n \leq 30\) |
4 | 12 | \(n \leq 150\) |
5 | 24 | \(n \leq 2000\) |
6 | 20 | \(\sum{n} \leq 3 \times 10^5\) |
7 | 16 | No additional constraints |
Sample Input 1 | Sample Output 1 |
5
|
14
|
The optimal solution for the first testcase is \(\{c_i\} = \{d_i\} = \{1\}\).
An optimal solution for the second testcase is \(\{c_i\} = \{1, 3\}, \{d_i\} = \{2, 3\}\).
The optimal solution for the third testcase is \(\{c_i\} = \{3, 4\}, \{d_i\} = \{3, 5\}\).
The optimal solution for the fourth testcase is \(\{c_i\} = \{d_i\} = \{2, 3, 4, 6\}\).
The optimal solution for the fifth testcase is \(\{c_i\} = \{2, 3, 4, 5, 6\}, \{d_i\} = \{1, 2, 3, 4, 6\}\).
Subtask | Score |
---|---|
1 | 12 |
2 | 8 |
3 | 8 |
4 | 12 |
5 | 24 |
6 | 20 |
7 | 16 |