题目连接:
http://codeforces.com/contest/493/problem/C
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 - b is maximum. If there are several such scores, find the one in which number a is maximum.
Sample Input
3
1 2 3
2
5 6
Sample Output
9:6
Hint
题意
A队在n个距离位置投进了篮球,B队在m个位置。
现在让你来划3分线,然后使得A队分数减去B队分数最大。
题解:
暴力枚举三分线,肯定三分线就n+m+4种可能,都暴力枚举一边,然后对于每一个队伍,我二分找到有多少个二分球,和多少个三分球就好了
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
int n,m;
int a[maxn],b[maxn];
int Ans=-1e9,Ans2,Ans3;
void update(int x,int y,int z)
{
if(Ans<x)Ans=x,Ans2=y,Ans3=z;
if(Ans==x&&y>Ans2)Ans=x,Ans2=y,Ans3=z;
}
void get(int x)
{
int l=0,r=m,ans=1;
while(l<=r)
{
int mid=(l+r)/2;
if(b[mid]<=x)ans=mid,l=mid+1;
else r=mid-1;
}
int l2=0,r2=n,ans2=1;
while(l2<=r2)
{
int mid=(l2+r2)/2;
if(a[mid]<=x)ans2=mid,l2=mid+1;
else r2=mid-1;
}
update(ans2*2+(n-ans2)*3-ans*2-(m-ans)*3,ans2*2+(n-ans2)*3,ans*2+(m-ans)*3);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
scanf("%d",&m);
for(int i=1;i<=m;i++)
scanf("%d",&b[i]);
sort(a+1,a+1+n);
sort(b+1,b+1+m);
update(2*n-2*m,2*n,2*m);
update(3*n-3*m,3*n,3*m);
for(int i=1;i<=n;i++)
get(a[i]);
get(a[1]-1);
get(a[n]+1);
for(int i=1;i<=m;i++)
get(b[i]);
get(b[1]-1);
get(b[m]+1);
printf("%d:%d\n",Ans2,Ans3);
}