H - Vasya and Basketball

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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 - bis maximum. If there are several such scores, find the one in which number a is maximum.

Sample Input

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
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std; typedef long long LL;
const int N = 200005;
LL n, m, a[N], b[N], mi, mj, ans;
int main()
{ scanf("%I64d", &n);
for(int i = 0; i < n; ++i) scanf("%I64d", &a[i]); scanf("%I64d", &m);
for(int i = 0; i < m; ++i) scanf("%I64d", &b[i]); sort(a, a + n);
sort(b, b + m);
mi = n * 3;
mj = m * 3;
ans = mi - mj; for(int i = 0; i < n; ++i)
{
if(a[i] == a[i + 1] && i != n - 1) continue;//注意例子 5 2 2 2 2 2 3 2 2 2, 说明在枚举一串的时候, 相同值的应该用上界来尝试
LL d = a[i];
LL pos = upper_bound(b, b + m, d) - b;//注意uuper_bound 求上界的时候, 如果找到了, 还是返回 最后那个位置 + 1, 而如果要找的数大于数组里面的max, 返回的是 最大下标
LL aa = (i + 1) * 2 + (n - i - 1) * 3;
LL bb;
if(d >= b[m - 1]) bb = 2 * m;
else
bb = (pos) * 2 + (m - pos) * 3;
if(aa - bb > ans || (aa - bb == ans && aa > mi)) {
ans = aa - bb;
mi = aa;
mj = bb;
}
} for(int i = 0; i < m; ++i)
{
if(b[i] == b[i + 1] && i != m - 1) continue;
LL d = b[i];
LL pos2 = upper_bound(a, a + n, d) - a;
LL bb = (i + 1) * 2 + (m - i - 1) * 3;
LL aa;
if(d >= a[n - 1]) aa = 2 * n;
else
aa = (pos2) * 2 + (n - pos2) * 3;
if(aa - bb > ans || (aa - bb == ans && aa > mi)) {
ans = aa - bb;
mi = aa;
mj = bb;
// printf("[%d %d %d]\n", ans, mi, mj);
}
}
printf("%I64d:%I64d\n", mi, mj);
}

  

Codeforce 493c的更多相关文章

  1. Codeforce - Street Lamps

    Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...

  2. Codeforce Round #216 Div2

    e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...

  3. Codeforce 水题报告(2)

    又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...

  4. codeforce 375_2_b_c

    codeforce 375_2 标签: 水题 好久没有打代码,竟然一场比赛两次卡在边界条件上....跪 b.题意很简单...纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了 #i ...

  5. codeforce 367dev2_c dp

    codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...

  6. 三维dp&codeforce 369_2_C

    三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...

  7. 强连通分量&hdu_1269&Codeforce 369D

    强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...

  8. 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D

    [树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...

  9. 解题报告:codeforce 7C Line

    codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...

随机推荐

  1. 【编程题目】有 n 个长为 m+1 的字符串,如果某个字符串的最后 m 个字符与某个字符串的前 m 个字符匹配...

    37.(字符串)有 n 个长为 m+1 的字符串,如果某个字符串的最后 m 个字符与某个字符串的前 m 个字符匹配,则两个字符串可以联接,问这 n 个字符串最多可以连成一个多长的字符串,如果出现循环, ...

  2. MyEclipse在线安装maven插件最新地址

    http://repository.sonatype.org/content/sites/forge-sites/m2e/0.10.0/S/20100209-0800/

  3. JS图表插件(柱形图、饼状图、折线图)

    http://www.open-open.com/lib/view/open1406378625726.html

  4. [Android Pro] 使用apktool工具遇到could not decode arsc file的解决办法

    转:http://www.cnblogs.com/sage-blog/p/4323049.html 最近使用APKtool工具反编译APK老是提示不成功,错误如下: Exception in thre ...

  5. iOS - 定制多样式二维码

    二维码/条形码是按照某种特定的几何图形按一定规律在平台(一维/二维方向上)分布的黑白相间的图形纪录符号信息.使用若干个与二进制对应的几何形体来表示文字数值信息.   最常见的二维码功能包括信息获取.网 ...

  6. ora-01400 无法将NULL插入 ID 解决方法

    问题描述:由于工作原因,把部分 字段改了,大体这样 StatementCallback; uncategorized SQLException for SQL [insert into test(sc ...

  7. 微软MSMQ消息队列的使用

    首先在windows系统中安装MSMQ 一.MSMQ交互 开发基于消息的应用程序从队列开始.MSMQ包含四种队列类型: 外发队列:消息发送到目的地之前,用它来临时存储消息. 公共队列:在主动目录中公布 ...

  8. 【php全局变量和静态变量、静态方法的使用方法】

    php全局变量使用关键字global声明,静态变量使用static声明,静态变量的使用可以使用 类名::变量名 示例代码: <?php //全局变量global 的用法和静态变量的使用 glob ...

  9. 图结构练习——最小生成树(kruskal算法(克鲁斯卡尔))

    图结构练习——最小生成树 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述  有n个城市,其中有些城市之间可以修建公路,修建不同的公 ...

  10. 使用 Log4Net 记录日志

    第一步:下载Log4Net 下载地址:http://logging.apache.org/log4net/download_log4net.cgi 把下载的  log4net-1.2.11-bin-n ...