C. Vasya and Basketball(思维)

题目描述
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 d meters, and a throw is worth 3 points if the distance is larger than d d meters, where d 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 d . Help him to do that.

输入格式
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 d meters, and a throw is worth 3 points if the distance is larger than d d meters, where d 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 d . Help him to do that.

输出格式
Print two numbers in the format a:b — the score that is possible considering the problem conditions where the result of subtraction a-b a−b is maximum. If there are several such scores, find the one in which number a a is maximum.

题意翻译
题意简述
Vasya 记录了一场篮球赛中两支队伍每次命中的投篮离篮筐的距离。他知道每一次成功的投篮可以得到 22 分或 33 分。如果一次命中的投篮离篮筐不超过 d(d \ge 0)d(d≥0) 米则得 22 分,否则得 33 分。Vasya 可以指定一个 dd,同时他希望第一支队伍的分数 aa 减去第二支队伍的分数 bb 最大。

请你帮他求出这个 dd。

输入格式
第一行一个正整数 n(1\leq n \leq 2·10^5)n(1≤n≤2⋅10
5
),表示第一支队伍的命中数。

接下来一行 nn 个正整数 a_1,a_2,···,a_n(1\leq a_i \leq 2·10^9)a
1

,a
2

,⋅⋅⋅,a
n

(1≤a
i

≤2⋅10
9
),表示每一次命中离篮筐的距离。

第一行一个正整数 m(1\leq m \leq 2·10^5)m(1≤m≤2⋅10
5
),表示第一支队伍的命中数。

接下来一行 mm 个正整数 b_1,b_2,···,b_n(1\leq b_i \leq 2·10^9)b
1

,b
2

,⋅⋅⋅,b
n

(1≤b
i

≤2⋅10
9
),表示每一次命中离篮筐的距离。

输出格式
输出一行两个整数 aa,bb,分别表示两队的分数,中间用符号 : 分隔。您应该最大化 a-ba−b。

翻译贡献者 U108949

输入输出样例
输入 #1 复制
3
1 2 3
2
5 6
输出 #1 复制
9:6
输入 #2 复制
5
6 7 8 9 10
5
1 2 3 4 5
输出 #2 复制
15:10

分析:

可以把d设置在两队每个命中的距离的位置,逐一进行比较,找出a-b最大的那个位置,注意d也可以设置在所有命中距离之前的位置。并且a-b之差初始化要设置为负无穷大,因为可能a-b的最大值为负数。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 4e5+10;
map<ll,int> p1,p2;
ll c[N],h1[N],h2[N];
int main()
{
	int n,m;
	scanf("%d",&n);
	ll x;
	int k=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		if(p1[x]==0) c[++k]=x;
		p1[x]++;
	}
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%lld",&x);
		if(p1[x]==0&&p2[x]==0) c[++k]=x;
		p2[x]++;
	}
	sort(c+1,c+1+k);
	for(int i=1;i<=k;i++)
	{
		h1[i]+=h1[i-1]+p1[c[i]];
		h2[i]+=h2[i-1]+p2[c[i]];
	}
	ll ans=-10000000000,a,b,sum;
	for(int i=0;i<=k;i++)
	{
		sum=h1[i]*2+(h1[k]-h1[i])*3-h2[i]*2-(h2[k]-h2[i])*3;
		if(sum>ans)
		{
			a=h1[i]*2+(h1[k]-h1[i])*3;
			b=h2[i]*2+(h2[k]-h2[i])*3;
			ans=sum;
		}
	}
	printf("%lld:%lld",a,b);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值