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 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 thand meters, whered is somenon-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 ofd. 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 follown integer numbers — the distances of throwsai (1≤ai≤2·109).

Then follows number m (1≤m≤2·105) — the number of the throws of the second team. Then followm integer numbers — the distances of throws ofbi (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 subtractiona-b is maximum. If there are several such scores, find the one in which numbera is maximum.

Sample test(s)

Input

31 2 325 6

Output

9:6

Input

56 7 8 9 1051 2 3 4 5

Output

15:10

题目链接:

题目大意:有两个队比赛投篮,A队投了n球距离为ai,B队投了m球距离为bi,其中有两分有三分,给一个三分线,使得A队总得分减去B队总得分的值最大,若有多种可能取A队得分最多的那组,输出A队和B队最后的比分

题目分析:先把比分排序,初始都认为两队得的都是两分,设两个变量ab和ba分别表示A比B多1分的次数和B比A多一分的次数(其实就是A和B三分球的次数),模拟更新一下ab和ba的值即可,,详细见程序注释

#include <iostream> #include <algorithm>#define ll long long using namespace std; int const MAX = 200005; ll a[MAX], b[MAX], n, m; int main() {cin >> n;for(int i = 0; i < n; i++)cin >> a[i];cin >> m;for(int i = 0; i < m; i++)cin >> b[i];sort(a, a + n);sort(b, b + m);int j = m – 1;ll x = 0, y = 0, ab = n, ba = m;for(int i = n – 1; i >= 0; i–){//B比A距离远一次则以当前三分线a[i],B比A多一次三分while(j >= 0 && a[i] <= b[j]){j–;y++;}//以当前的a[i]做三分线,A的三分次数加1x++;//根据差值更新A,B三分球的次数,注意这里的等号不能少!//题目要求多组解取A得分最高的那组就体现在这里,如果两次差值//相同,那就让A,B都得3分,这样差值不会变,但比2分时的得分高if(x – y >= ab – ba){ab = x;ba = y;}}//如果最后A所能得到的三分次数都比B小那就把所有投篮都当作2分//因为要求A的总分减去B的总分最大,在这种情况下如果算上3分//显然sumA – sumB的值就会变小,因为sumB大了if(ab < ba)ab = ba = 0;//累加上三分的次数及a比b多一分和b比a多一分的次数cout << n * 2 + ab << ":" << m * 2 + ba << endl; }

分明是比谁记的都清楚,比谁都更加在意,

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

相关文章:

你感兴趣的文章:

标签云: