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. Oracle_Q&A_03

    1.先导入SQL文件 执行语句查看表信息 select * from student;--学生信息--(stunum,stuname,classid)select * from class;--班级信 ...

  2. json对象转字符串与json字符串转对象

    1.概述: 我们在编程时进场会遇到json对象转字符串,或者字符串转对象的情况. 2.解决办法: json.parse()方法是将json字符串转成json对象. json.stringfy()方法是 ...

  3. HtmlParser 2.0 中文乱码问题

    对于HTMLParser 2.0 工具包我们需要修改其中的Page.java文件使其适用中文的html文件分析. 主要是把protected static final String DEFAULT_C ...

  4. 【浅墨Unity3D Shader编程】之二 雪山飞狐篇:Unity的基本Shader框架写法&amp;颜色、光照与材质

    本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/40955607 作者:毛星云(浅墨)  ...

  5. TortoiseGit和msysGit安装及使用笔记(windows下使用上传数据到GitHub)[转]

    TortoiseGit和msysGit安装及使用笔记(windows下使用上传数据到GitHub) Git-1.7.11-preview+GitExtensions244SetupComplete+T ...

  6. Android原理揭秘系列之一动态墙纸

    Livewallpaper,即动态墙纸,是Android的一大3D特色功能,用户可以在桌面选择加载动态墙纸,让自己的手机桌面背景旋动起来. 相对于静态桌面壁纸,动态墙纸可以展示各种动态变化的背景,而与 ...

  7. C++ operator关键字(重载操作符)(转)

    operator是C++的关键字,它和运算符一起使用,表示一个运算符函数,理解时应将operator=整体上视为一个函数名. 这是C++扩展运算符功能的方法,虽然样子古怪,但也可以理解:一方面要使运算 ...

  8. QT程序启动界面的使用

    当程序的初始化工作比较多,程序可能启动较长时间后,窗口才会显示出来,用户没准会抱怨程序响应的慢. 为了改善用户体验,最好在程序初始化这段时间显示logo,或者其他信息提示用户程序已启动.QT提供了QS ...

  9. 解决Linux下Oracle中文乱码的一些心得体会 ,转自

    以下转自 http://blog.itpub.net/29151695/viewspace-1173238/ 最近在linux上安装完oracle 10gR2后,又遇到了字符集乱码的问题,之前在网上找 ...

  10. 常用mysql笔记

    1.insert into ... values insert into tables (col1,col2) values (1,2),(2,3); 2.insert into ... select ...