The New Kid

View as PDF

Submit solution


Points: 5
Time limit: 2.0s
Memory limit: 64M

Authors:
Problem type

Jagdeep is moving into a neighbourhood near Massey. Since Jagdeep is such a popular kid, he already knows every single person on the street he is looking to move to. There are N houses that are unoccupied (1 \le N \le 1,000), but there are also M houses with people in them who he doesn’t like (1 \le M \le 3,000). Each house is up to 1,000,000,000 meters away from the front of the street, and each house is on the street. What is the position of the house that is the furthest away from any abode of any person Jagdeep doesn’t like?

Input Specifications

The two integers N and M in that order on a single line, separated by a space. On each of the next N lines, there will be a single non-negative integer denoting the position of an empty house. On each of the next M lines, there will be a single non-negative integer denoting the position of a home of someone Jagdeep doesn’t like.

Output Specifications

The position of an empty house that is also farthest of any of the empty houses from any house of any person Jagdeep doesn’t like. If there are multiple empty houses that tie for farthest distance, output the one closest to the front of the street.

Sample Input

3 5
3
24
18
2
23
7
14
25

Sample Output

18

Comments

There are no comments at the moment.