Codeforces Round #281 (Div. 2) C. 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 - bis 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

 题意: 给出两个球队进球的距离,要你选择一个距离d ,进球距离 <= d 的进球得两分,大于的得三分

问你a队得分-b队得分的最大差距。

思路: d是进球距离里面的某个数,然后我们可以先离散化距离,然后枚举d,

枚举的时候用树状数组计算两只球队得分。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<set>
#include<algorithm>
#define maxn 400010
#define INF 0x3f3f3f3f
using namespace std ;

int xt[2][maxn] ,sz;
int a[200010],b[200010],num[maxn] ;

void insert(int id,int x)
{
    while(x<=sz)
    {
        xt[id][x]++;
        x += (x&-x) ;
    }
}
int sum(int id,int x)
{
    int ans=0;
    while(x>0)
    {
        ans += xt[id][x] ;
        x -= (x&-x) ;
    }
    return ans;
}

int main()
{
    int i,j,n,m,k ;
    int xx,yy,x,y;
    int t1,t2;
    while(scanf("%d",&n) != EOF)
    {
        memset(xt,0,sizeof(xt));
        sz=0;
        for( i = 1 ; i <= n ;i++)
        {
            scanf("%d",&a[i]) ;
            num[sz++]=a[i] ;
        }
        scanf("%d",&m) ;
        for( i = 1 ; i <= m ;i++)
        {
            scanf("%d",&b[i]) ;
            num[sz++]=b[i] ;
        }
        sort(num,num+sz) ;
        sz=unique(num,num+sz)-num ;
        for( i = 1 ; i <= n;i++)
        {
            x=lower_bound(num,num+sz,a[i])-num;
            insert(0,x+1) ;
        }
        for( i = 1 ; i <= m;i++)
        {
            x=lower_bound(num,num+sz,b[i])-num;
            insert(1,x+1) ;
        }
        xx=-INF;
        yy=0;
        for( i = -1 ; i < sz ;i++)
        {
            x=sum(0,i+1);
            y=sum(1,i+1);
            t1=x*2+(n-x)*3;
            t2=y*2+(m-y)*3;
            if(t1-t2>xx-yy||(t1-t2==xx-yy&&t1>xx))
            {
                xx=t1;yy=t2;
            }
        }
        printf("%d:%d\n",xx,yy) ;
    }
    return 0 ;
}
View Code

 

posted @ 2014-12-04 10:29  _log__  阅读(202)  评论(0编辑  收藏  举报