Codeforce 493c
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #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); } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧