codeforces A. TL 题解
来源:互联网 发布:类似于echo的软件 编辑:程序博客网 时间:2024/04/28 14:20
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 2a ≤ 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.
The first line contains two integers n, m (1 ≤ n, m ≤ 100). The second line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the running time of each of the n correct solutions in seconds. The third line contains m space-separated positive integers b1, b2, ..., bm (1 ≤ bi ≤ 100) — the running time of each of mwrong solutions in seconds.
If there is a valid TL value, print it. Otherwise, print -1.
3 64 5 28 9 6 10 7 11
5
这句话难读懂:
We can also say that a solution passes the system testing with some "extra" time if for its running time, a seconds, an inequality 2a ≤ v holds.
就是说:如果一个AC的解决方案的运行时间是a,满足2*a <= v,那么就说这个运行时间通过而且有"extra"时间(a)
void TLjudge(){int n, m, minVal = 1<<30, maxVal = 1<<31, a = 0;cin>>n>>m;while (n--){cin>>a;if (a < minVal) minVal = a;if (a > maxVal) maxVal = a;}int ans = max(minVal*2, maxVal);bool ok = true;while (m--){cin>>a;if (a <= ans){ok = false;break;}}if (ok) cout<<ans;else cout<<-1;};
- codeforces A. TL 题解
- Codeforces Round #203 (Div. 2) A. TL
- CodeForces 350A TL(基础题)
- A. TL
- codeforces A. Cakeminator 题解
- codeforces A. Array题解
- codeforces 150A 题解
- codeforces 10月1日 A题 TL--水题
- Codeforces A. Double Cola 题解
- codeforces A. IQ test 题解
- codeforces A. Supercentral Point 题解
- codeforces A. k-String 题解
- Codeforces 115A Party 题解
- Codeforces 522A Reposts 题解
- Codeforces 76A Gift 题解
- Codeforces 489A SwapSort 题解
- Codeforces 575A Fibonotci 题解
- Codeforces 416A Guess a number! 题解
- Configure Oracle 11gR2 RAC 一节点执行root.sh脚本报错
- 线程的状态转换
- [数学+dfs] ZOJ 3753 Simple Equation
- 2.1 派生对话框类
- 实现scheme解释器的疑问
- codeforces A. TL 题解
- android颜色集合
- 使用布尔选项
- Glusterfs目录ls性能优化方案分析
- 于红尘路上,播种微笑诗行
- java Swing 之单选按钮和复选按钮的使用
- 添加子命令(Adding subcommands)
- 在有图片的网页地址栏中敲入这些,然后就~~
- java Swing 文本框的使用