C. Vasya and Basketball
Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful the throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it's made from doesn ' t exceed some value of D meters, and a throw is worth 3 points if the distance are larger than D meters, where D is some non-negative int Eger.
Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of th E second team) to be maximum. For that he can mentally choose the value of D. Help him.
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 10 5)-the number of the throws of thesecond team. Then follow m integer numbers-the distances of throws of bi (1≤ bi ≤2 109).
Output
Print numbers in the format a:b-the score that's possible considering the problem conditions where the result of subtractiona - b is maximum. If There is several such scores, find the one in which number a is maximum.
Sample Test (s)
input
3
1 2 3
2
5 6
Output
9:6
Test Instructions: Shooting game, give you two people into the distance of basketball, let you find a D so that the distance of less than equal to the shot is divided into 2, greater than the distance of D is divided into 3, while making a-B score difference Maximum If there is a a, the same situation, try to make a maximum
Solving: Sort by difference at the same time a as big as possible, on the line
///Meek#include <bits/stdc++.h>using namespaceStd;typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#definePB Push_backinline ll read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){ if(ch=='-') f=-1; ch=GetChar (); } while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar (); }returnx*F;}//****************************************Const intn=2000005;#defineMoD 10000007#defineINF 2000000007#defineMAXN 10000ll Lna,lnm,n,a[n],b[n],m;structss{ll X,inch, Index;} T[i+N];structSSS {ll x,aa; int inch;} W[n+N];intCMP (ss S1,ss S2) {if(s1.x==s2.x)returnS1.inch<s2.inch; returns1.x<s2.x;}intcmp2 (SSS s1,sss s2) {if(s1.x==s2.x)returns1.aa<S2.aa; Else returns1.x<s2.x;}intMain () {n=read (); intk=0; for(intI=1; i<=n;i++) {scanf ("%i64d",&A[i]); s[++k].x=A[i]; S[k].inch=0; S[k].index=i; } m=read (); for(intI=1; i<=m;i++) {scanf ("%i64d",&B[i]); s[++k].x=B[i]; S[k].inch=1; S[k].index=i; } sort (S+1, s+k+1, CMP); ll L=0, r=0; for(intI=1; i<=k;i++) { if(S[i].inch==0) {L++; } Elser++; w[i].x= (l*2+ (n-l) *3)-(r*2+ (M-R) *3); W[i].aa= (l*2+ (n-l) *3); W[i].inch=i; } w[++k].x=n*3-m*3; W[k].aa= (n3); W[k].inch=-1; w[++k].x=n*2-m*2; W[k].aa= (n2); W[k].inch=-2; Sort (W+1, w+k+1, CMP2); ll Ansl=0, ansr=0; Ansl=w[k].aa;ansr=w[k].aa-w[k].x; cout<<ansl<<":"<<ansr<<Endl; return 0;}
Code
Codeforces Round #281 (Div. 2) C. Vasya and Basketball sort