WC '17 Contest 2 S1 - Keeping Score

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 1.4s
Memory limit: 64M

Author:
Problem type
Woburn Challenge 2017-18 Round 2 - Senior Division

There's nothing like a bit of friendly competition, even when your life is on the line! Legolas and Gimli have taken to counting how many enemies they're each able to kill in each confrontation, in an effort to one-up one another.

During the battle of Helm's Deep, Legolas killed L (2L200000) enemies, the ith of which had a strength level of SLi (1SLi109). Meanwhile, Gimli killed G (1G<L) enemies, the ith of which had a strength level of SGi (1SGi109).

Though Gimli killed fewer enemies than Legolas did, he's not about to admit defeat to the elf so easily. As such, he's gotten the idea to introduce a new rule: "All enemies with strength levels smaller than X don't count" (for some positive integer X no larger than 109). Help Gimli find any value of X which would cause him to "win" (in other words, such that Gimli killed strictly more enemies with strength levels greater than or equal to X than Legolas did). If no possible value of X would have this result, output -1 instead.

Subtasks

In test cases worth 7/14 of the points, L1000.

Input Specification

The first line of input consists of two space-separated integers, L and G.
L lines follow, the ith of which consists of a single integer SLi (for i=1L).
G lines follow, the ith of which consists of a single integer SGi (for i=1G).

Output Specification

Output a single integer, any valid value of X which would cause Gimli to win, or -1 if there's no such value.

Sample Input 1

Copy
5 4
84
6
105
54
30
91
84
28
66

Sample Output 1

Copy
60

Sample Input 2

Copy
2 1
3
3
3

Sample Output 2

Copy
-1

Sample Explanation 2

In the first case, if X=60, then Legolas's score will be 2 (with his 1st and 3rd killed enemies counting), while Gimli's score will be 3. Note that there exist other valid values of X which would also be accepted.

In the second case, if X3, then both Legolas's score will be 2 and Gimli's will be 1. If X>3, then both scores will be 0. Either way, Gimli can't win.


Comments

There are no comments at the moment.