sequence_loj

Sequence

There are two sequences of positive integers {ai} and {bi}, 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 {ci} and {di} of size K such that

  • 1c1<c2<<cKn
  • 1d1<d2<<dKn
  • |{c1,c2,,cK}{d1,d2,,dK}|L
Your task is then to maximize i=1Kaci+i=1Kbdi.

Input format

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 a1,a2,,an.

The third line of each testcase will contain n integers b1,b2,,bn.

Output format

Output one line for each testcase, each containing a single integer - the maximum sum of elements as described.

Limits

1T10.
1n106.
1LKn2×105
1ai,bi,109.
Subtask # Score Constraints
1 12 n10
2 8 n18
3 8 n30
4 12 n150
5 24 n2000
6 20 n3×105
7 16 No additional constraints

Samples

Sample Input 1 Sample Output 1
5
1 1 1
7
7
3 2 1
4 1 2
1 4 2
5 2 1
4 5 5 8 4
2 1 7 2 7
6 4 1
1 5 8 3 2 4
2 6 9 3 1 7
7 5 4
1 6 6 6 5 9 1
9 5 3 9 1 4 2
14
12
27
45
62

The optimal solution for the first testcase is {ci}={di}={1}.
An optimal solution for the second testcase is {ci}={1,3},{di}={2,3}.
The optimal solution for the third testcase is {ci}={3,4},{di}={3,5}.
The optimal solution for the fourth testcase is {ci}={di}={2,3,4,6}.
The optimal solution for the fifth testcase is {ci}={2,3,4,5,6},{di}={1,2,3,4,6}.



Submitting to 'sequence_loj'


You're not logged in! Click here to login


Submitting to 'sequence_loj'


You're not logged in! Click here to login


Submitting .cpp to 'sequence_loj'


You're not logged in! Click here to login

Time Limit: 1 Seconds
Memory Limit: 1024MB
Your best score: 0
Source: LOJ #3158

Subtask Score
1 12
2 8
3 8
4 12
5 24
6 20
7 16