Codeforces 493C. Vasya and Basketball【暴力+二分】

来源:互联网 发布:餐饮软件全国排名 编辑:程序博客网 时间:2024/06/06 09:44

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 ofd meters, and a throw is worth 3 points if the distance is larger thand meters, where d is somenon-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 ofd. 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 follown integer numbers — the distances of throwsai (1 ≤ ai ≤ 2·109).

Then follows number m (1 ≤ m ≤ 2·105) — the number of the throws of the second team. Then followm integer numbers — the distances of throws ofbi (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 subtractiona - b is maximum. If there are several such scores, find the one in which numbera is maximum.

Examples
Input
31 2 325 6
Output
9:6
Input
56 7 8 9 1051 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