#P6877. [JOI 2020 Final] 只不过是长的领带 / Just Long Neckties
[JOI 2020 Final] 只不过是长的领带 / Just Long Neckties
Description
JOI Company invented a kind of necktie. There are neckties in total, numbered from to . The length of the -th necktie is .
JOI Company held a party. There are employees at the party. At the beginning, the -th employee was wearing a necktie of length .
The party proceeds as follows:
- First, the boss of JOI Company, Mr. JOI, selects one necktie and takes it away.
- Then, each employee chooses one necktie, making sure that no two employees choose the same necktie.
- 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 , and chooses a necktie of length , then the employee feels a weirdness of . The overall weirdness of the party is the maximum weirdness among all employees.
Mr. JOI defines as the minimum possible overall weirdness after he selects the -th necktie.
Mr. JOI wants to know the exact value of .
Input Format
The first line contains an integer , representing the number of employees.
The second line contains integers , representing the length of each necktie.
The third line contains integers , representing the length of the necktie each person was wearing at the beginning.
Output Format
Output one line with integers , 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 -th necktie. Then the employees may choose as follows:
- Employee chooses the -st necktie, and feels weirdness .
- Employee chooses the -nd necktie, and feels weirdness .
- Employee chooses the -rd necktie, and feels weirdness .
The overall weirdness is .
But we can further reduce the overall weirdness:
- Employee chooses the -nd necktie, and feels weirdness .
- Employee chooses the -rd necktie, and feels weirdness .
- Employee chooses the -st necktie, and feels weirdness .
The overall weirdness is .
Therefore, .
Constraints
This problem uses bundled testdata.
- Subtask 1 (1 pts): .
- Subtask 2 (8 pts): .
- Subtask 3 (91 pts): no additional constraints.
For of the testdata:
- .
- .
- .
Notes
Translated from The 19th Japanese Olympiad in Informatics, Final Round A 長いだけのネクタイ.
Translated by ChatGPT 5
京公网安备 11011102002149号