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.

Sample test(s)
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

ab排序

for一遍在a数组枚举d=a[i]-1,这样可以保证最优(因为d=a[i]-1一定比d=a[i]-2优)

然后二分d在b数组中的位置就可以知道有多少个2分多少个3分了

还要考虑d=inf的情况

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m;
int a[200010];
int b[200010];
int now2;
int ans1,ans2,mx,mx2;
int main()
{
n=read();
for(int i=1;i<=n;i++)a[i]=read();
m=read();
for(int j=1;j<=m;j++)b[j]=read();
sort(a+1,a+n+1);
sort(b+1,b+m+1);
int kk=a[1]-1,s1=3*n,s2=0;
for (int i=1;i<=m;i++)if (b[i]>kk)s2+=3;else s2+=2;
mx=s1-s2;mx2=s1;
ans1=s1;ans2=s2;
if (2*n-2*m>mx||2*n-2*m==mx&&2*n>mx2)
{
mx=2*n-2*m;mx2=2*n;
ans1=2*n;ans2=2*m;
}
for (int now=1;now<=n;now++)
{
if (a[now]==a[now-1])continue;
now2=lower_bound(b+1,b+m+1,a[now])-b;
int res1=3*(n-now+1)+2*(now-1),res2=3*(m-now2+1)+2*(now2-1);
if (res1-res2>mx||res1-res2==mx&&res1>mx2)
{
mx=res1-res2;
mx2=res1;
ans1=res1;
ans2=res2;
}
}
printf("%d:%d\n",ans1,ans2);
}

其实因为排序完b数组是递增的,所以可以直接用一个指针来模拟二分

cf493C Vasya and Basketball的更多相关文章

  1. Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分

    C. Vasya and Basketball time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  2. Codeforces 493C - Vasya and Basketball

    C. Vasya and Basketball 题目链接:http://codeforces.com/problemset/problem/493/C time limit per test 2 se ...

  3. Codeforces Round #281 (Div. 2) C. Vasya and Basketball 暴力水题

    C. Vasya and Basketball time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. Codeforces Round #281 (Div. 2) C. Vasya and Basketball 排序

    C. Vasya and Basketball   Vasya follows a basketball game and marks the distances from which each te ...

  5. Vasya and Basketball CodeForces - 493C

    Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows ...

  6. 【Codeforces 493C】Vasya and Basketball

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 枚举三分线(离散后)的位置 然后根据预处理的前缀和,快速算出两个队伍的分数. [代码] #include <bits/stdc++.h& ...

  7. codeforces 493 C Vasya and Basketball

    题意:给出三分线的值d,分别有两支队伍,如果小于等于d,得2分,如果大于d,得三分,问使得a-b最大时的a,b 一看到题目,就想当然的去二分了----啥都没分出来---55555555 后来才知道不能 ...

  8. Codeforce 493c

    H - Vasya and Basketball Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  9. Codeforces Round #281 (Div. 2)

    题目链接:http://codeforces.com/contest/493 A. Vasya and Football Vasya has started watching football gam ...

随机推荐

  1. 让iframe调用页面的背景透明

    需求:在一个div里面嵌套一个iframe(src="ui.html"),div有背景图片,要让iframe里的内容透明地显示在div层上. 刚开始直接把iframe放在div中, ...

  2. IntelliJ IDEA常见问题及解决方法

    1.IDEA导入项目后,源码.java文件图标带有红色圆圈,圆圈中间是个J: 该现象的原因是由于项目未把该路径指定为源码路径.解决方法: 在project Structure中(快捷键ctrl+alt ...

  3. 使用nvm来管理nodejs版本

    nvm 是 Mac 下的 node 管理工具,有点类似管理 Ruby 的 rvm,如果是需要管理 Windows 下的 node,官方推荐是使用 nvmw 或 nvm-windows .nvm主要用来 ...

  4. GitHub 小试

    GitHub是什么? 它是用来进行版本控制的,就是用来保存项目的地方. 但是项目要是运行,还是需要你本地的环境,它只不过是用来保存代码罢了. GitHub如何操作? 可以通过客户端进行代码提交,更新. ...

  5. Java基础知识强化58:经典排序之二叉树排序(BinaryTreeSort)

    1. 二叉树排序 二叉树排序的描述也是一个递归的描述, 所以二叉树排序的构造自然也用递归的: 二叉排序树或者是一棵空树,或者是具有下列性质的二叉树: (1)若左子树不空,则左子树上所有结点的值均小于它 ...

  6. Mysql相关操作

    1. 如何更改系统环境变量PATH?vim /etc/profile  加入 PATH=$PATH:/usr/local/mysql/bin2. 默认mysql安装好后,并没有root密码,如何给ro ...

  7. Draggable(拖动)组件

    一.加载方式 //class 加载方式 <div id="box" class="easyui-draggable" style="width: ...

  8. compass的使用

    compass常用的一些命令 compass create 创建新Compass项目 compass init  为已存在项目添加compass compass clean 移动已生成的文件和缓存 c ...

  9. 通过Url传多个参数方法

    MVC3通过URL传值,一般情况下都会遇到[从客户端(&)中检测到有潜在危险的 Request.Path 值]的问题 这个问题的解决方法,我的其他博文已经有了说明,这里给出连接[从客户端(&a ...

  10. 基本 XAML 语法指南

    我们介绍了 XAML 语法规则,以及用于描述 XAML 语法中存在的限制或选项的术语.当出现以下情况时你会发现本主题很有用:不熟悉 XAML 语言的使用,希望加强对术语或某些语法部分的理解,或者对 X ...