#P13994. 【MX-X19-T3】「LAOI-14」Another Round

【MX-X19-T3】「LAOI-14」Another Round

Description

Given a positive integer nn and two integer sequences a=(a1,,an)a = (a_1, \ldots, a_n) and b=(b1,,bn)b = (b_1, \ldots, b_n) of length nn, where bib_i is guaranteed to be non-negative, but aia_i may be negative.

Define the notation [n][n] to represent the set {i1in}\{ i \mid 1 \le i \le n \}.

For each k[n]k \in [n], you need to select a subset SS of [n][n] with size kk. Under this constraint, find the maximum value of

$$\Bigl( \max_{i \in S} a_i \Bigr) - \Bigl( \operatorname*{mex}_{i \in S} b_i \Bigr).$$

Note: mexiSbi\displaystyle \operatorname*{mex}_{i \in S} b_i denotes the minimum non-negative integer that does not appear in {biiS}\{ b_i \mid i \in S \}.

Input Format

The input contains multiple test cases.

The first line contains an integer TT, indicating the number of test cases. For each test case:

  • The first line contains a positive integer nn.
  • The second line contains nn integers a1,,ana_1, \ldots, a_n.
  • The third line contains nn non-negative integers b1,,bnb_1, \ldots, b_n.

Output Format

For each test case, output nn lines. The ii-th line should contain one integer, which is the answer when k=ik = i.

1
3
1 2 3
0 0 1
3
1
1
4
4
9 1 2 0
9 3 7 8
5
4 8 8 9 4
4 9 0 7 8
6
3 9 4 6 2 5
6 4 6 5 8 2
5
5 2 2 4 4 
0 1 4 2 1
9
9
9
9
9
9
9
9
8
9
9
9
9
9
9
4
4
4
4
2
2
6
0 0 0 0 0 0
6 5 2 7 1 6
6
6 5 0 7 9 2
0 0 0 0 0 0
0
0
0
0
0
0
8
8
8
8
8
8

Hint

【Sample Explanation #1】

When k=1k=1, let S={3}S = \{3\}, then the answer is 30=33 - 0 = 3.

When k=2k=2, let S={2,3}S = \{2, 3\}, then the answer is 32=13 - 2 = 1.

When k=3k=3, let S={1,2,3}S = \{1, 2, 3\}, then the answer is 32=13 - 2 = 1.

【Data Range】

This problem uses bundled testing.

Subtask ID n\sum n \le Special Properties Score
11 1010 C 1111
22 200200 1717
33 20002000 2323
44 10610^6 AC 1919
55 BC 77
66 10510^5 C 2222
77 10610^6 None 11
  • Special Property A: ai=0a_i = 0.
  • Special Property B: bi=0b_i = 0.
  • Special Property C: T=1T = 1.

For all test cases, 1T,n,n1061 \le T, n, \sum n \le 10^6, 109ai109-10^{9} \le a_i \le 10^{9}, 0bi1090 \le b_i \le 10^{9}.

Translated by DeepSeek V3.1