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. 【XLL 框架库函数】 Excel/Excel12f

    Excel/Excel12f 这两个库函数分别包装了 C API 中的 Excel4 和 Excel12 函数,它们会检查函数没有参数时是否为零,它将表明创建临时的 XLOPER 或 XLOPER12 ...

  2. html与js传json值给php

    //一段js代码 var data = {}, act = [], list = []; $('.set').find('input, textarea').each(function() { act ...

  3. WaxPatch中demo注意问题

    问题一 https://github.com/mmin18/WaxPatch网址中提供的demo是可以运行,但是存在一个问题,如果把patch.zip换成自己的并且上传到自己的服务器(github), ...

  4. JS获取浏览器高度 并赋值给类

    在给网站做轮播焦点图的时候,如果需要全屏的话,可以用下面的jQuery来获取浏览器高度,然后赋值给类. $(window).load(function () { var maxHeight = 0; ...

  5. webservice 简单入门 (NLY)

    1,创建webservice服务器端 搭建网站,创建webservice webservice.cs中的代码 namespace WebApplication1 { /// <summary&g ...

  6. NSDatePicker && NSDate

    UIDatePicker *datePicker = [[UIDatePicker alloc]init]; datePicker.datePickerMode = UIDatePickerModeD ...

  7. Jquery.Datatables 基本设置的中文注解

    $(document).ready(function() { $('#example').dataTable({ "sScrollX": "100%", //表 ...

  8. git中使用.gitignore文件

    在进行协作开发代码管理的过程中,常常会遇到某些临时文件.配置文件.或者生成文件等,这些文件由于不同的开发端会不一样,如果使用git add . 将所有文件纳入git库中,那么会出现频繁的改动和push ...

  9. php开发(CI框架使用)

    年前接了一个外包项目,要求使用PHP,琢磨来琢磨去,感叹道PHP框架实在是太多了!去知乎搜索一轮,最后决定使用CI, 相关议论如下:https://www.zhihu.com/question/216 ...

  10. Oracle优化 -- 关于Database Buffer Cache相关参数DB_CACHE_SIZE的优化设置

    select size_for_estimate, buffers_for_estimate ,ESTD_PHYSICAL_READ_factor,ESTD_PHYSICAL_READS from v ...