Vasya and Basketball CodeForces - 493C
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.
Example
3
1 2 3
2
5 6
9:6
5
6 7 8 9 10
5
1 2 3 4 5
15:10
两支队伍a,b,a进了n球 下面n个数为a队进球距离球筐的距离,
b进了m球,下面m个数为b队进球距离球筐的距离,
问三分线为多少时a队与b队的比分差值最大
输出比分 答案优先输出a大的。
temp1=upper_bound(a,a+n,a[i])-a;
temp1=temp1*2+(n-temp1)*3;
upper_bound返回的是第一个大于a[i]的元素的指针,
数组从0开始,所以temp对应的就是小于a[i]的元素的个数
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 #include<queue> 6 using namespace std; 7 int a[200010],b[200010]; 8 int main() { 9 int n,m,x,y; 10 while(scanf("%d",&n)!=EOF){ 11 for (int i=0 ;i<n ;i++) scanf("%d",&a[i]); 12 scanf("%d",&m); 13 for (int i=0 ;i<m ;i++) scanf("%d",&b[i]); 14 if (n>=m) { 15 x=3*n; 16 y=3*m; 17 }else { 18 x=2*n; 19 y=2*m; 20 } 21 int temp1,temp2; 22 sort(a,a+n); 23 sort(b,b+m); 24 for (int i=0 ;i<n ;i++ ){ 25 temp1=upper_bound(a,a+n,a[i])-a; 26 temp2=upper_bound(b,b+m,a[i])-b; 27 temp1=temp1*2+(n-temp1)*3; 28 temp2=temp2*2+(m-temp2)*3; 29 if (temp1-temp2==x-y){ 30 if (temp1>x){ 31 x=temp1; 32 y=temp2; 33 } 34 }else if (temp1-temp2>x-y){ 35 x=temp1; 36 y=temp2; 37 } 38 } 39 for (int i=0 ;i<m ;i++ ){ 40 temp1=upper_bound(a,a+n,b[i])-a; 41 temp2=upper_bound(b,b+m,b[i])-b; 42 temp1=temp1*2+(n-temp1)*3; 43 temp2=temp2*2+(m-temp2)*3; 44 if (temp1-temp2==x-y){ 45 if (temp1>x){ 46 x=temp1; 47 y=temp2; 48 } 49 }else if (temp1-temp2>x-y){ 50 x=temp1; 51 y=temp2; 52 } 53 } 54 printf("%d:%d\n",x,y); 55 } 56 return 0; 57 }