Vasya and Basketball codeforces 493c 二分二分

B - Vasya and Basketball

Crawling in process...Crawling failedTime Limit:2000MS    Memory Limit:262144KB     64bit IO Format:%I64d & %I64u  

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 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.

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
题意:就是说给了两组数据,让你找到一个界限,使得第一组数的和与第二组数的差最大,的一组数的和是这样算的:不这个界限大的每个是三分,比这个界限小的每个是两份,对于这个数的话如果按两分算,那么所有与它相同的都是两分
思路:二分二分,我自己都炸了,做了好长时间,测试数据就一直错错,好不容易钱多少组过了,到38组超时了,顿时就不开心了,后来仔细的想想,看了别人博客介绍,就换了思路,果然直接ac,言归正传吧,刚开始的时候我是从两列数的最小的枚举到两列数的最大,这样就超时了,以为如果隔得数据相差太大,这样就算二分也会费很多时间如给1和999999999这样的话明显超时,后来改变思路,就是枚举第一个数列的每个数进行算差最大和枚举第二列数算差最大,在加上0和最大这两条界限的,得出来的就是最大差了。。
AC代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

int n;
int m;
long long a[300000];
long long b[300000];
long long inf = 0x7fffffff;
int main() {
    scanf("%d",&n);
    for(int i = 0; i < n; i++) {
        scanf("%I64d",&a[i]);
    }
    scanf("%d",&m);
    for(int i = 0; i < m; i++) {
        scanf("%I64d",&b[i]);
    }

    sort(a,a+n);
    sort(b,b+m);
    long long sum = n*3-m*3;
    long long aa=n*3,bb=m*3;

    for(long long i = 0; i < n; i++) {
        int k = lower_bound(a,a+n,a[i])-a;
        int g = lower_bound(b,b+m,a[i])-b;
        long long kk = 3*(n-k)+2*k;
        long long gg = 3*(m-g)+2*g;
        if(kk-gg > sum) {
            sum = kk-gg;
            aa=kk;
            bb=gg;
        }
        if(kk-gg == sum) {
            if(aa<kk) {
                aa=kk;
                bb=gg;
            }
        }
    }
    for(long long i = 0; i < m; i++) {
        int k = lower_bound(a,a+n,b[i])-a;
        int g = lower_bound(b,b+m,b[i])-b;
        long long kk = 3*(n-k)+2*k;
        long long gg = 3*(m-g)+2*g;
        if(kk-gg > sum) {
            sum = kk-gg;
            aa=kk;
            bb=gg;
        }
        if(kk-gg == sum) {
            if(aa<kk) {
                aa=kk;
                bb=gg;
            }
        }
    }
    if(n*2-m*2 > sum) {
        aa=n*2;
        bb=m*2;
    }
    if(n*2-m*2 == sum) {
        if(aa < n*2) {
            aa=n*2;
            bb=m*2;
        }
    }
    printf("%I64d:%I64d\n",aa,bb);
    return 0;
}



二分二分就是不好想,对于菜鸟简直是难做,但我们一定要坚持做下去,加油加油。。

你可能感兴趣的:(二分)