CF 281div2 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.



题意:在篮球比赛当中,给你n个距离和m个距离,问你如何设定三分线使得第一个人与第二个人的分数差最大,输出比分,如果分数差一样,选择第一个得分最高的那个人。

范围:1<=n,m<=200000 1<=距离<=20000000.

思路:其实思路比较简单,二分距离。用第一个人的得分去选择三分线,然后去二分得到第二个的得分。直接记录就可以,时间复杂度为nlogm,完全可行。

当然在这里借用了STL里的upper_bound();函数去查找第二个人根据三分线所得的分。用法自行补脑。


代码如下:

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<cstdlib>
#include<cmath>
#define PI 2*asin(1.0)
#define LL __int64
const int  MOD = 1e9 + 7;
const int N = 2e5 + 15;
const int INF = (1 << 30) - 1;
const int letter = 130;
using namespace std;
int n, m;
int a[N], b[N];
int main()
{
    while(cin >> n)
    {
        for(int i = 0; i < n; i++) cin >> a[i];
        sort(a, a + n);
        cin >> m;
        for(int i = 0; i < m; i++) cin >> b[i];
        sort(b,b+m);
        LL  maxa = 2*n, maxb = 2*m;
        LL  max1 = maxa - maxb;
        for(LL i = 0; i < n; i++)
        {
            LL ans = i * 2 + (n - i) * 3;
            LL vs = upper_bound(b, b + m, a[i] - 1) - b; ///重点,sort是基础
            LL bns = vs * 2 + (m - vs) * 3;
            if((ans - bns) > max1 || (ans - bns == max1 && ans > maxa))
            {
                max1 = ans - bns;
                maxa = ans, maxb = bns;
            }
        }
        printf("%I64d:%I64d\n", maxa, maxb);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值