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.

Examples
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球队的n次投篮距离,给你B球队的m次投篮距离。让你自己定义一个三分线,然后使得A队得分与B队得分差值最大(如果有得分相同的情况,需要使A队得分最大)。


思路:


1、首先,三分线的枚举分成三种类型:

①设定三分线为0.

②设定三分线为无穷大.

③设定三分线为min(A球队最小射程,B球队最小射程)----max(A球队最大射程,B球队最大射程)之间的一个距离,其实要设在其之间,相当于设定在n+m个射程内的某一个。


2、那么我们暴力枚举n+m+2(这个+2是指上述第一第三种情况)个射程内的一个射程作为三分线,然后分别在排序过后的A数组中二分查找第一个大于等于这个三分线的位子记为posa,那么此时A球队得分为(n-posa)*3+posa*2,同理,找这样一个位子在B数组中,记为posb,那么B球队的得分为(m-posb)*3+posb*2,然后在这个过程中维护一个最大差值,最终输出最优解即可。


Ac代码:


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[200050];
int b[200050];
int c[400050];
int main()
{
    int n,m,cont;
    scanf("%d",&n);
    cont=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        c[cont++]=a[i];
    }
    scanf("%d",&m);
    for(int i=0;i<m;i++)
    {
        scanf("%d",&b[i]);
        c[cont++]=b[i];
    }
    sort(a,a+n);
    sort(b,b+m);
    c[cont++]=0;
    c[cont++]=2000000050;
    int maxn=-0x3f3f3f3f;
    int ansa=-1;
    int ansb=-1;
    for(int i=0;i<cont;i++)
    {
        int sanfen=c[i];
        int l=0;
        int r=n;
        int posa=-1;
        while(r>=l)
        {
            int mid=(l+r)/2;
            if(a[mid]>=sanfen)
            {
                posa=mid;
                r=mid-1;
            }
            else l=mid+1;
        }
        l=0;r=m;
        int posb=-1;
        while(r>=l)
        {
            int mid=(l+r)/2;
            if(b[mid]>=sanfen)
            {
                posb=mid;
                r=mid-1;
            }
            else l=mid+1;
        }
        int defena,defenb;
        if(posa==-1)defena=n*2;
        else defena=(n-posa)*3+posa*2;
        if(posb==-1)defenb=m*2;
        else defenb=(m-posb)*3+posb*2;
        if(defena-defenb>maxn)
        {
            maxn=defena-defenb;
            ansa=defena;
            ansb=defenb;
        }
        else if(defena-defenb==maxn)
        {
            if(defena>ansa)
            {
                ansa=defena;
                ansb=defenb;
            }
        }
    }
    printf("%d:%d\n",ansa,ansb);
}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值