#P6877. [JOI 2020 Final] 只不过是长的领带 / Just Long Neckties

[JOI 2020 Final] 只不过是长的领带 / Just Long Neckties

Description

JOI Company invented a kind of necktie. There are N+1N+1 neckties in total, numbered from 11 to N+1N+1. The length of the ii-th necktie is AiA_i.

JOI Company held a party. There are NN employees at the party. At the beginning, the jj-th employee was wearing a necktie of length BjB_j.

The party proceeds as follows:

  1. First, the boss of JOI Company, Mr. JOI, selects one necktie and takes it away.
  2. Then, each employee chooses one necktie, making sure that no two employees choose the same necktie.
  3. Finally, they take off the neckties they were wearing at first, and put on the chosen neckties.

If an employee was initially wearing a necktie of length bb, and chooses a necktie of length aa, then the employee feels a weirdness of max{ab,0}\max\{a-b,0\}. The overall weirdness of the party is the maximum weirdness among all employees.

Mr. JOI defines CkC_k as the minimum possible overall weirdness after he selects the kk-th necktie.

Mr. JOI wants to know the exact value of CkC_k.

Input Format

The first line contains an integer NN, representing the number of employees.
The second line contains N+1N+1 integers AiA_i, representing the length of each necktie.
The third line contains NN integers BjB_j, representing the length of the necktie each person was wearing at the beginning.

Output Format

Output one line with N+1N+1 integers CkC_k, representing the minimum overall weirdness after selecting each necktie.

3
4 3 7 6
2 6 4
2 2 1 1
5
4 7 9 10 11 12
3 5 7 9 11
4 4 3 2 2 2

Hint

Explanation for Sample 1

Let us assume that Mr. JOI selects the 44-th necktie. Then the employees may choose as follows:

  • Employee 11 chooses the 11-st necktie, and feels weirdness 22.
  • Employee 22 chooses the 22-nd necktie, and feels weirdness 00.
  • Employee 33 chooses the 33-rd necktie, and feels weirdness 33.

The overall weirdness is 33.

But we can further reduce the overall weirdness:

  • Employee 11 chooses the 22-nd necktie, and feels weirdness 11.
  • Employee 22 chooses the 33-rd necktie, and feels weirdness 11.
  • Employee 33 chooses the 11-st necktie, and feels weirdness 00.

The overall weirdness is 11.

Therefore, C4=1C_4=1.

Constraints

This problem uses bundled testdata.

  • Subtask 1 (1 pts): N10N \le 10.
  • Subtask 2 (8 pts): N2000N \le 2000.
  • Subtask 3 (91 pts): no additional constraints.

For 100%100\% of the testdata:

  • 1N2×1051 \le N \le 2 \times 10^5.
  • 1Ai1091 \le A_i \le 10^9.
  • 1Bj1091 \le B_j \le 10^9.

Notes

Translated from The 19th Japanese Olympiad in Informatics, Final Round A 長いだけのネクタイ.

Translated by ChatGPT 5