codeforces 10月1日 A题 TL--水题

第一次做CF...可惜不会注册比赛...提交的时候交不上去...大哭

然后做了一道题之后,发现...网有问题...打不开了......

TMD  算了...写个博客然后做作业然后睡觉觉好了


A. TL


time limit per test:2 seconds


memory limit per test:256 megabytes


input:standard input


output:standard output




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:


1. v 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 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.




Input


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 m wrong solutions in seconds. 




Output


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




Sample test(s)






Input
3 6
4 5 2
8 9 6 10 7 11






Output
5




Input
3 1
3 4 5
6






Output
-1


怎一个水字了得...

注意extra time 比如一个right answer 时间为t  那么t*2需要小于等于v


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 102

int main()
{
    int n,m,i,j;
    int r[N],w[N],f,max1,min1;

    while(scanf("%d%d",&n,&m)!=EOF)
    {
        f=0;
        scanf("%d",&r[0]);
        max1=r[0];
        for(i=1;i<n;i++)
        {
            scanf("%d",&r[i]);
            if(max1<r[i])
            {

                max1=r[i];
            }
        }
        for(i=0;i<n;i++)
        {
            if(r[i]*2<max1){f=1;break;}
        }
        scanf("%d",&w[0]);
        min1=w[0];
        for(i=1;i<m;i++)
        {
            scanf("%d",&w[i]);
            if(min1>w[0])min1=w[0];
        }
        if(f==1&&max1<min1)printf("%d\n",max1);
        else printf("-1\n");
    }

    return 0;
}


  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值