#TP0000023. Chuẩn bị thêm một chiếc hộp (Prepare Another Box)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chuẩn bị thêm một chiếc hộp (Prepare Another Box)
Prepare Another Box
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Takahashi has toys and boxes. Toy has size , and box has size . A toy can be placed in a box only when the box is at least as large as the toy.
Takahashi will purchase exactly one additional box of a positive integer size . He must then put all toys into the boxes, with exactly one toy per box. Find the smallest possible . If no choice of makes this possible, print -1.
Input
- The first line contains , the number of toys.
- The second line contains integers , the toy sizes.
- The third line contains integers , the sizes of the existing boxes.
Output
Print the minimum positive integer size of the additional box, or -1 if no solution exists.
Subtasks
- Subtask 1 (20 points): ; for all ; for all .
- Subtask 2 (30 points): ; for all ; for all .
- Subtask 3 (50 points): ; for all ; for all .
Examples
Input
4
5 2 3 7
6 2 8
Output
3
Explanation
Buying a new box of size allows toys of sizes to be placed into boxes of sizes , respectively. Every toy fits, and each box holds one toy. If , the toys of sizes and cannot both be assigned while preserving the two sufficiently large boxes for toys . Thus is minimal.