CodeForces 493C Vasya and Basketball

C. Vasya and Basketball
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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, where d 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 test(s)
input
3
1 2 3
2
5 6
output
9:6
input
5
6 7 8 9 10
5
1 2 3 4 5
output
15:10

题目大意:a,b两队投篮,给出各自投篮时距篮筐的距离,找一个三分线的位置使得A队得分-B队得分最大,如果差值相等,找使A对得分高的三分线,求出比分。

解题思路:以A,B队的投篮位置枚举三分线,通过计算可知B队2分个数-A队2分个数(用cur记录)最大时满足条件,比较求出答案。

解题过程:wa点:考虑cur值相同时的交换条件。注意容易超时,采用效率高的算法或优化。

代码如下:
#include <cstdio>
#include <algorithm>
using namespace std;
#define LL long long
const int maxn=2000005;
int n,m;
LL a[maxn],b[maxn], c[maxn];
int main()
{
    int k,i,j,sk,sj,maxx=-4000010,cur,an=0,bn=0,cnt=0;
    LL ans1,ans2;
    scanf("%ld",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        c[cnt++]=a[i];
    }
    sort(a,a+n);
    scanf("%ld",&m);
    for(i=0;i<m;i++)
    {
        scanf("%lld",&b[i]);
        c[cnt++]=b[i];
    }
    sort(b,b+m);
    sort(c,c+cnt);
    cnt=unique(c,c+cnt)-c;//把要枚举的三分线不重复地存入数组c[]中。
    c[cnt]=c[cnt-1]+1;
    cnt++;
    sk=0,sj=0;
    for(i=0;i<cnt;i++)
    {
        if(a[n-1]<c[i])//A队小于三分线的距离个数,即2分个数为k
            k=n;
        else
        for(k=sk;k<n;k++)
            if(a[k]>=c[i])
            {
                sk=k;
                break;
            }
        if(b[m-1]<c[i])//B队小于三分线的距离个数,即2分个数为j
            j=m;
        else
        for(j=sj;j<m;j++)
            if(b[j]>=c[i])
            {
                sj=j;
                break;
            }
		cur=j-k;
        if(maxx<cur||(maxx==cur&&(m-j)>(n-k)))//注意判断条件
        {
            maxx=cur;
            an=k;
            bn=j;
        }
    }
    ans1=2*an+3*(n-an);
    ans2=2*bn+3*(m-bn);
    printf("%lld:%lld\n", ans1,ans2);
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值