CF350A.TL
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
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 n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set v seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most v seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, a seconds, an inequality 2_a_ ≤ v holds.
As a result, Valera decided to set v seconds TL, that the following conditions are met:
- v is a positive integer;
- all correct solutions pass the system testing;
- at least one correct solution passes the system testing with some "extra" time;
- all wrong solutions do not pass the system testing;
- value v is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist.
瓦莱拉想为 CodeSecrof 比赛准备一道题目。他目前已有一道题,并希望为其设定一个时间限制(Time Limit,简称 TL)。
瓦莱拉编写了 n 个正确解法。对于每个正确解法,他已知其运行时间(单位:秒)。他还编写了 m 个错误解法,并对每个错误解法也已知其运行时间(单位:秒)。
假设瓦莱拉将该题的 TL 设为 v 秒。那么我们称一个解法通过系统测试,当且仅当它的运行时间不超过 v 秒。进一步地,若某个解法的运行时间为 a 秒,且满足不等式 2a≤v,则称该解法以一定的“余量”通过系统测试。
最终,瓦莱拉决定选择一个整数 v 作为 TL,使得以下条件全部满足:
- v 是一个正整数;
- 所有正确解法均能通过系统测试;
- 至少有一个正确解法能以一定的“余量”通过系统测试;
- 所有错误解法均不能通过系统测试;
- 在所有满足条件 1–4 的 v 中,v 取最小值。
请帮助瓦莱拉找出最合适的 TL;若不存在满足条件的 TL,请说明其不存在。
输入格式
The first line contains two integers n, m (1 ≤ n, m ≤ 100). The second line contains n space-separated positive integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 100) — the running time of each of the n correct solutions in seconds. The third line contains m space-separated positive integers _b_1, _b_2, ..., b__m (1 ≤ b__i ≤ 100) — the running time of each of m wrong solutions in seconds.
第一行包含两个整数 n、m(1 ≤ n, m ≤ 100)。
第二行包含 n 个用空格分隔的正整数 a1, a2, ..., an(1 ≤ ai ≤ 100)——表示 n 个正确解法各自的运行时间(单位:秒)。
第三行包含 m 个用空格分隔的正整数 b1, b2, ..., bm(1 ≤ bi ≤ 100)——表示 m 个错误解法各自的运行时间(单位:秒)。
输出格式
If there is a valid TL value, print it. Otherwise, print -1.
如果存在有效的 TL 值,则输出该值;否则输出 -1。
输入输出样例
输入#1
3 6 4 5 2 8 9 6 10 7 11
输出#1
5
输入#2
3 1 3 4 5 6
输出#2
-1
输入解题思路,AI测评打分。不知道怎么写?