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

Input

31 2 325 6

Output

9:6

Input

56 7 8 9 1051 2 3 4 5

Output

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 }


原文地址:https://www.cnblogs.com/qldabiaoge/p/8516570.html

时间: 2024-07-31 23:45:09

Vasya and Basketball CodeForces - 493C的相关文章

codeforces 493C Vasya and Basketball (枚举+模拟+思维)

C. Vasya and Basketball time limit per test 2 seconds memory limit per test 256 megabytes 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 point

Codeforces Round #281 (Div. 2) C. Vasya and Basketball 排序

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 throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from does

codeforces 493C Vasya and Basketball(二分)

传送门:点击打开链接 题目大意: 有2个队打篮球,然后告诉你,A队投了N次蓝,分别的距离,B队投了M篮,分别的距离. As we all know, 篮球有个三分线,然后让你找一个三分线出来,使得A队的得分-B队得分最大.差值相同的情况下,找比分最大的. 压线算2分. 解题思路: 假设一个投篮线.在X处 那么很容易 算出每个队的得分情况.(只需要排序 然后二分哪些值是小于等于他的就好了). 那么就枚举投篮线就好,只需要在N+M个数字之间枚举.然后再增加一个0和INF 2条线. 总结一下吧: 打了

codeforces 493 C Vasya and Basketball

题意:给出三分线的值d,分别有两支队伍,如果小于等于d,得2分,如果大于d,得三分,问使得a-b最大时的a,b 一看到题目,就想当然的去二分了----啥都没分出来---55555555 后来才知道不能二分,因为随着d的增大,两个队的得分都会逐渐减少,但是两个队伍的得分的差值的单调性却不知道 是这一篇这样讲的 http://www.cnblogs.com/huangxf/p/4142760.html 然后就依次枚举d的值,维护一个最大值 1 #include<iostream> 2 #inclu

Vasya And Array CodeForces - 1187C (构造)

Vasya And Array 题意: 给你一个序列,再给你一些区间 t = 1时说明这些区间时非递减的 t = 0 时说明这些区间至少有一对数字 arr[i] > arr[i - 1] 思路: 只要左边的区间必然右边的区间大就好了 , 非递减区间中的数字都赋值为一样的数字 因为n只有1000 , 把初值cnt赋值为1e6 , 每次给区间赋值的时候 -1000 把第一种情况的区间赋值完成之后,剩下的还没有赋值的部分,都赋值为单调递减序列就可以了 1 #include<cstdio> 2

C. Vasya and Basketball

·真的是发现每题都有坑... 这题主要目的是求一个3分的分界线.题意就不多说了,主要说下自己的思路: 思路: 定义结构体,标识每个分数属于哪个队伍,然后将两个队伍的得分放在同一个数组中,从小到大进行排序. 之后从后向前.(即从大分数向小分数) 按照分数计算出Max{num1-num2}:(num1为大于等于当前分数的队伍一的投球个数:num2为大于等于当前分数的队伍二的投球个数.) 算出临界点的球数差值对应的分数就为3分与2分得分界线. 之后进行计算得分输出即可. ·注意一个坑点: If the

cf 493C

A - Vasya and Basketball Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 493C Appoint description:  System Crawler  (2014-12-04) Description Vasya follows a basketball game and marks the

Codeforce 493c

H - Vasya and Basketball Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 493C Description Vasya follows a basketball game and marks the distances from which each team makes a throw. He k

Codeforces Round #281 (Div. 2) 解题报告 A.B.C.D.

A - Vasya and Football 纯模拟..比较坑的是会有不符合足球常识的地方.. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #inc