Codeforce 493c
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
3
1 2 3
2
5 6
9:6
5
6 7 8 9 10
5
1 2 3 4 5
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的更多相关文章
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- Codeforce Round #216 Div2
e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...
- Codeforce 水题报告(2)
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...
- codeforce 375_2_b_c
codeforce 375_2 标签: 水题 好久没有打代码,竟然一场比赛两次卡在边界条件上....跪 b.题意很简单...纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了 #i ...
- codeforce 367dev2_c dp
codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...
- 三维dp&codeforce 369_2_C
三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...
- 强连通分量&hdu_1269&Codeforce 369D
强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...
- 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D
[树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...
- 解题报告:codeforce 7C Line
codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...
随机推荐
- HDU 5752 Sqrt Bo (思维题) 2016杭电多校联合第三场
题目:传送门. 题意:一个很大的数n,最多开5次根号,问开几次根号可以得到1,如果5次还不能得到1就输出TAT. 题解:打表题,x1=1,x2=(x1+1)*(x1+1)-1,以此类推.x5是不超过l ...
- UUID UDID
Google搜索关键字Difference between UUID and UDID,在stackoverflow看见解释,我翻译过来,如下所述. UUID(Universally Unique I ...
- Mac 下查看 Android Studio 的 SHA1的方法
cmd -> ->cd .android ->keytool -v -list -keystore debug.keystore 默认口令:android ************* ...
- 转:不再以讹传讹,GET和POST的真正区别
如果有人问你,GET和POST,有什么区别?你会如何回答? 我的经历 前几天有人问我这个问题.我说GET是用于获取数据的,POST,一般用于将数据发给服务器之用. 这个答案好像并不是他想要的.于是他继 ...
- MVC学习笔记---各种上下文context
0 前言 AspNet MVC中比较重要的上下文,有如下: 核心的上下文有HttpContext(请求上下文),ControllerContext(控制器上下文) 过滤器有关有五个的上下文Actio ...
- MVC基础知识 – 1.抽象工厂模式
1.调用规则 2.简单工厂 问题:在List.aspx里怎么new一个业务层? 2.1.再在 02SBLL 解决方案里建一个类库 BLL_Tow,也有一个 Users.cs 2.2.建立一个工厂 2. ...
- java web开发环境配置
一:安装jdk http://www.java.com/zh_TW/ 二:下载tomcat,这里是zip版.http://tomcat.apache.org/download-70.cgi 三:在 ...
- Java集合源码学习(二)ArrayList分析
>>关于ArrayList ArrayList直接继承AbstractList,实现了List. RandomAccess.Cloneable.Serializable接口,为什么叫&qu ...
- 【翻译十】java-固定锁和同步
Intrinsic Locks and Synchronization Synchronization is built around an internal entity known as the ...
- 拷贝,集合,函数,enumerate,内置函数
1.拷贝 字符串和数字.赋值 id一样 import copy #提供拷贝功能 copy.copy() #原来的和现在的一起修改,不用修改时用浅copy,节省内存,复制最外层 copy.deepcop ...