CF350A.TL

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.

Valera has written nn correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote mm wrong solutions and for each wrong solution he knows its running time (in seconds).

Let's suppose that Valera will set vv seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most vv seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, aa seconds, an inequality 2a<=v2a<=v holds.

As a result, Valera decided to set vv seconds TL, that the following conditions are met:

  1. vv is a positive integer;
  2. all correct solutions pass the system testing;
  3. at least one correct solution passes the system testing with some "extra" time;
  4. all wrong solutions do not pass the system testing;
  5. value vv is minimum among all TLs, for which points 11 , 22 , 33 , 44 hold.

Help Valera and find the most suitable TL or else state that such TL doesn't exist.

输入格式

The first line contains two integers nn , mm ( 1<=n,m<=1001<=n,m<=100 ). The second line contains nn space-separated positive integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=1001<=a_{i}<=100 ) — the running time of each of the nn correct solutions in seconds. The third line contains mm space-separated positive integers b1,b2,...,bmb_{1},b_{2},...,b_{m} ( 1<=bi<=1001<=b_{i}<=100 ) — the running time of each of mm wrong solutions in seconds.

输出格式

If there is a valid TL value, print it. Otherwise, print -1.

输入输出样例

  • 输入#1

    3 6
    4 5 2
    8 9 6 10 7 11
    

    输出#1

    5
  • 输入#2

    3 1
    3 4 5
    6
    

    输出#2

    -1
    
首页