2 seconds
256 megabytes
standard input
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.
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).
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.
3
1 2 3
2
5 6
9:6
5
6 7 8 9 10
5
1 2 3 4 5
15:10
思路:我怎么zz的写了个二分;
n*3-n小于等于d的个数-m*2-m大于d的个数最大;
显然需要求n小于等于d的个数+m大于d的个数最小;
我是暴力二分,排个序好像可以把二分取消了;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
int a[N],b[N],sa,sb;
int l[N<<];
int flag,n,m;
int check(int x)
{
int pos1=upper_bound(a,a+n,x)-a;
int pos2=upper_bound(b,b+m,x)-b;
pos2=m-pos2;
return pos1+pos2;
}
int main()
{
flag=;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]),l[flag++]=a[i];
scanf("%d",&m);
for(int i=;i<m;i++)
scanf("%d",&b[i]),l[flag++]=b[i];
sort(a,a+n);
sort(b,b+m);
l[flag++]=;
l[flag++]=2e9+;
sort(l,l+flag);
flag=unique(l,l+flag)-l;
int minn=inf,ans;
for(int i=;i<flag;i++)
{
int v=check(l[i]);
if(v<minn)
{
minn=v;
ans=l[i];
}
}
int ji=,lu=;
for(int i=;i<n;i++)
if(a[i]<=ans)
ji++;
for(int i=;i<m;i++)
if(b[i]>ans)
lu++;
printf("%d:%d",*n-ji,*m+lu);
return ;
}