• Codeforce 493c


    H - Vasya and Basketball
    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    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 Input

    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

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    using namespace std;
    
    typedef long long LL;
    const int N = 200005;
    LL n, m, a[N], b[N], mi, mj, ans;
    int main()
    {
    
        scanf("%I64d", &n);
        for(int i = 0; i < n; ++i) scanf("%I64d", &a[i]);
    
        scanf("%I64d", &m);
        for(int i = 0; i < m; ++i) scanf("%I64d", &b[i]);
    
        sort(a, a + n);
        sort(b, b + m);
        mi = n * 3;
        mj = m * 3;
        ans = mi - mj;
    
        for(int i = 0; i < n; ++i)
        {
            if(a[i] == a[i + 1] && i != n - 1) continue;//注意例子 5 2 2 2 2 2  3 2 2 2, 说明在枚举一串的时候, 相同值的应该用上界来尝试
            LL d = a[i];
            LL pos = upper_bound(b, b + m, d) - b;//注意uuper_bound 求上界的时候, 如果找到了, 还是返回 最后那个位置 + 1, 而如果要找的数大于数组里面的max, 返回的是 最大下标
            LL aa = (i + 1) * 2 + (n - i - 1) * 3;
            LL bb;
            if(d >= b[m - 1]) bb = 2 * m;
            else
                bb = (pos) * 2 + (m - pos) * 3;
            if(aa - bb > ans || (aa - bb == ans && aa > mi)) {
                ans = aa - bb;
                mi = aa;
                mj = bb;
            }
        }
    
    
        for(int i = 0; i < m; ++i)
        {
            if(b[i] == b[i + 1] && i != m - 1) continue;
            LL d = b[i];
            LL pos2 = upper_bound(a, a + n, d) - a;
            LL bb = (i + 1) * 2 + (m - i - 1) * 3;
            LL aa;
            if(d >= a[n - 1]) aa = 2 * n;
            else
                aa = (pos2) * 2 + (n - pos2) * 3;
            if(aa - bb > ans || (aa - bb == ans && aa > mi)) {
                ans = aa - bb;
                mi = aa;
                mj = bb;
             //  printf("[%d %d %d]
    ", ans, mi, mj);
            }
        }
        printf("%I64d:%I64d
    ", mi, mj);
    }
    

      

  • 相关阅读:
    字符串数组转化成json格式
    php关于发送和接受二进制数据
    thinkphp路径问题
    fread与file_get_contents读取函数文件
    php用urlencode、urldecode解决汉字乱码问题
    ThinkPHP关于数据库的操作
    Pytorch中torch.autograd ---backward函数的使用方法详细解析,具体例子分析
    TensorFlow tf.gradients的用法详细解析以及具体例子
    好用的函数,assert,random.sample,seaborn tsplot, tensorflow.python.platform flags 等,持续更新
    pytorch autograd backward函数中 retain_graph参数的作用,简单例子分析,以及create_graph参数的作用
  • 原文地址:https://www.cnblogs.com/orchidzjl/p/4664035.html
Copyright © 2020-2023  润新知