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 <map> #include <set> #include <cmath> #include <ctime> #include <queue> #include <vector> #include <cctype> #include <cstdio> #include <string> #include <cstring> #include <sstream> #include <cstdlib> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define pb push_back #define mp make_pair #define fillchar(a, x) memset(a, x, sizeof(a)) #define copy(a, b) memcpy(a, b, sizeof(a)) #define lson rt << 1, l, mid #define rson rt << 1|1, mid + 1, r typedef long long LL; typedef pair<int, int > PII; typedef unsigned long long uLL; template<typename T> void print(T* p, T* q, string Gap = " ") { int d = p < q ? 1 : -1; while(p != q) { cout << *p; p += d; if(p != q) cout << Gap; } cout << endl; } template<typename T> void print(const T &a, string bes = "") { int len = bes.length(); if(len >= 2)cout << bes[0] << a << bes[1] << endl; else cout << a << endl; } const LL INF = 1e17; const int MAXM = 1e2 + 5; const int MAXN = 2e5 + 5; int n, m; LL A[MAXN], B[MAXN]; LL z1, za1, zb1; void cal(int k) { LL fa = lower_bound(A, A + n, k) - A, ba = n - fa; LL za = fa * 2 + ba * 3; LL fb = lower_bound(B, B + m, k) - B,bb = m - fb; LL zb = bb * 3 + fb * 2; if(za - zb > z1) { za1 = za; zb1 = zb; z1 = za1 - zb1; } else if(za - zb == z1 && za > za1) { za1 = za; zb1 = zb; } } int main() { while(~scanf("%d", &n)) { for(int i = 0; i < n; i ++) { scanf("%lld", &A[i]); } scanf("%d", &m); for(int i = 0; i < m; i ++) { scanf("%lld", &B[i]); } sort(A, A + n); sort(B, B + m); z1 = -INF, za1 = 0, zb1 = 0; for(int i = 0; i < n; i ++) { cal(A[i] - 1); cal(A[i]); cal(A[i] + 1); } for(int i = 0; i < m; i ++) { cal(B[i] - 1); cal(B[i]); cal(B[i] + 1); } printf("%lld:%lld\n", za1, zb1); } return 0; }