#P5470. [NOI2019] 序列

    ID: 6206 远端评测题 2000ms 512MiB 尝试: 5 已通过: 1 难度: 9 上传者: 标签>贪心2019NOIO2优化优先队列模拟费用流

[NOI2019] 序列

Problem Description

Given two positive integer sequences {ai}\{a_i\} and {bi}\{b_i\} of length nn, where the indices are 1,2,,n1, 2, \cdots , n. You now need to choose exactly KK indices for each sequence, requiring that at least LL indices are chosen in both sequences, so that the total sum of the corresponding elements of these 2K2K indices is maximized.

Formally, you need to determine two sequences {ci}\{c_i\} and {di}\{d_i\} of length KK, where $1 \leq c_1 < c_2 < \cdots < c_K \leq n , 1 \leq d_1 < d_2 < \cdots < d_K \leq n$

and require that $\left \lvert \{c_1, c_2, \cdots , c_K\} \cap \{d_1, d_2, · · · , d_K\} \right \rvert \geq L$.

The goal is to maximize i=1Kaci+i=1Kbdi\sum^{K}_{i=1} a_{c_i} +\sum^{K}_{i=1} b_{d_i}.

Input Format

This input file contains multiple test cases.

The first line contains a positive integer TT indicating the number of test cases. Then every three lines describe one test case.

For each test case, the first line contains three integers n,K,Ln, K, L, with meanings as described in the statement.

For each test case, the second line contains nn integers representing the sequence {ai}\{a_i\}.

For each test case, the third line contains nn integers representing the sequence {bi}\{b_i\}.

Output Format

For each test case, output one line containing one integer, the answer.

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

Hint

More Samples

You can get more samples from the additional files.

Sample 2

See sequence/sequence2.in and sequence/sequence2.ans in the contestant directory.

Sample 3

See sequence/sequence3.in and sequence/sequence3.ans in the contestant directory.

Explanation for Sample 1

In the first test case, the chosen indices are: {ci}={1},{di}={1}\{c_i\} = \{1\} , \{d_i\} = \{1\}.

In the second test case, the chosen indices are: {ci}={1,3},{di}={2,3}\{c_i\} = \{1, 3\} , \{d_i\} = \{2, 3\}.

In the third test case, the chosen indices are: {ci}={3,4},{di}={3,5}\{c_i\} = \{3, 4\} , \{d_i\} = \{3, 5\}.

In the fourth test case, the chosen indices are: $\{c_i\} = \{2, 3, 4, 6\} , \{d_i\} = \{2, 3, 4, 6\}$.

In the fifth test case, the chosen indices are: $\{c_i\} = \{2, 3, 4, 5, 6\} , \{d_i\} = \{1, 2, 3, 4, 6\}$.

Constraints

For all test points: $T \leq 10 , 1 \leq \sum n \leq 10^6, 1 \leq L \leq K \leq n \leq 2 \times 10^5, 1 \leq a_i, b_i \leq 10^9$.

::cute-table{tuack}

Test Point ID nn\le n\sum n \le
131\sim3 1010 3×1053\times 10^5
454\sim5 1818 ^
676\sim7 3030
8108\sim10 150150
111611\sim16 2×1032\times 10^3
172117\sim21 2×1052\times 10^5
222522\sim25 ^ 10610^6

Translated by ChatGPT 5