Codeforces Round #281 (Div. 2) C. Vasya and Basketball
#include<cstdio> #include<iostream> #include<cstring> #include<queue> #include<set> #include<algorithm> #define maxn 400010 #define INF 0x3f3f3f3f using namespace std ; int xt[2][maxn] ,sz; int a[200010],b[200010],num[maxn] ; void insert(int id,int x) { while(x<=sz) { xt[id][x]++; x += (x&-x) ; } } int sum(int id,int x) { int ans=0; while(x>0) { ans += xt[id][x] ; x -= (x&-x) ; } return ans; } int main() { int i,j,n,m,k ; int xx,yy,x,y; int t1,t2; while(scanf("%d",&n) != EOF) { memset(xt,0,sizeof(xt)); sz=0; for( i = 1 ; i <= n ;i++) { scanf("%d",&a[i]) ; num[sz++]=a[i] ; } scanf("%d",&m) ; for( i = 1 ; i <= m ;i++) { scanf("%d",&b[i]) ; num[sz++]=b[i] ; } sort(num,num+sz) ; sz=unique(num,num+sz)-num ; for( i = 1 ; i <= n;i++) { x=lower_bound(num,num+sz,a[i])-num; insert(0,x+1) ; } for( i = 1 ; i <= m;i++) { x=lower_bound(num,num+sz,b[i])-num; insert(1,x+1) ; } xx=-INF; yy=0; for( i = -1 ; i < sz ;i++) { x=sum(0,i+1); y=sum(1,i+1); t1=x*2+(n-x)*3; t2=y*2+(m-y)*3; if(t1-t2>xx-yy||(t1-t2==xx-yy&&t1>xx)) { xx=t1;yy=t2; } } printf("%d:%d\n",xx,yy) ; } return 0 ; }