zoukankan      html  css  js  c++  java
  • 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);
    }
    

      

  • 相关阅读:
    dhcp服务配置
    配置一台时间服务器
    创建kvm虚拟机
    实现跳板机
    双向同步使用unison
    17、 Shell脚本题:编写个shell脚本将当前目录下大于10K的文件转移到/tmp目录下。
    find 命令
    权限管理:建立一个经理组
    使用sudo命令
    [转]tftp在put上传的时候显示File not found的解决办法
  • 原文地址:https://www.cnblogs.com/orchidzjl/p/4664035.html
Copyright © 2011-2022 走看看