codeforces Vasya and Basketball

Description

Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, whered is some non-negative integer.

Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that.

Input

The first line contains integer n (1 ≤ n ≤ 2·105) — the number of throws of the first team. Then follow n integer numbers — the distances of throws ai (1 ≤ ai ≤ 2·109).

Then follows number m (1 ≤ m ≤ 2·105) — the number of the throws of the second team. Then follow m integer numbers — the distances of throws of bi (1 ≤ bi ≤ 2·109).

Output

Print two numbers in the format a:b — the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum.

Sample Input

Input

31 2 325 6

Output

9:6

Input

56 7 8 9 1051 2 3 4 5

Output

15:10

题目意思:两个队投篮,在距离不大于(小于等于)len,就算2分,超过则3分,将要求第一队-第二队的分数是最大的,这里还暗含着如果差值一样大时,要取两队的分数大的那一组。

 

思路:该题主要运用了二分查找。我们可以把两队投篮的距离一次放入两个数组中,然后排序。(以升序为例吧)我们找到两个数组中最大的那个数max,i代表len的划分线,把i从0——max枚举,当等于0时就是所有都是3分的情况,不能省,我刚开始就忘了取0,因为看到分数是从1开始的,所以没有考虑。这样,知道了划分线我们就可以把两队的分数求出来。怎么求呢???我用的是stl中的lower_bound,我前面有博文介绍了stl中的3个二分法,lower_bound简单来说就是在一有序数列中,返回第一个等于或者大于n的数的指针,注意是指针!例如lower_bound(a,a+n,3)就是返回有序数组a,长度为n的第一个大于或等于3的数的指针。那样,我们知道题目中大于,等于完全就是得分不一样的了,所以我们还要分情况,是等于的就2分处理,大于的3分处理。总的来说,就是从0-max中枚举分数线,分别对两个数组用二分,再看返回的指针在数组相应的位置上存的数与当前枚举的数是大于还是等于关系,从而可以把两队的分数求出来。但是注意!!!!!有种情况千万不要忘了处理,就是3,3,3,3,3的情况,也就是后面有几个数都是相同的,假如当前面划分线是3,那么后面的3都代表2分了,所以这种情况我们还要看后一位是否与当前数相等,如果相等,再看下一位还跟当前位相等吗,这样来计算有几个数是相等的。最后还要处理一个,前面我们已经讲到了,当最大差是一样时,我们要分数最大的,意味着我们要更新分数。好了,我觉得挺详细了。

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值