fork(1) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int a, b, i, m, n, ia, ib, xa, xb, pos, res, res_a, res_b, aSize, bSize, score_a, score_b;
  6. vector< int > aS, bS;
  7. vector< pair< int, int > > aScore, bScore;
  8.  
  9. int main() {
  10. scanf( "%d", &n );
  11. for( i = 0; i < n; i++ ) {
  12. scanf( "%d", &a );
  13. aS.push_back( a );
  14. }
  15. scanf( "%d", &m );
  16. for( i = 0; i < m; i++ ) {
  17. scanf( "%d", &b );
  18. bS.push_back( b );
  19. }
  20. sort( aS.begin(), aS.end() );
  21. sort( bS.begin(), bS.end() );
  22. aScore.push_back( make_pair( aS[0], 1 ) );
  23. pos = 0;
  24. for( i = 1; i < n; i++ ) {
  25. if( aS[i] == aS[i - 1] ) {
  26. aScore[pos].second++;
  27. }
  28. if( aS[i] != aS[i - 1] ) {
  29. aScore.push_back( make_pair( aS[i], 1 ) );
  30. pos++;
  31. }
  32. }
  33. bScore.push_back( make_pair( bS[0], 1 ) );
  34. pos = 0;
  35. for( i = 1; i < m; i++ ) {
  36. if( bS[i] == bS[i - 1] ) {
  37. bScore[pos].second++;
  38. }
  39. if( bS[i] != bS[i - 1] ) {
  40. bScore.push_back( make_pair( bS[i], 1 ) );
  41. pos++;
  42. }
  43. }
  44. aScore.push_back( make_pair( aS[n - 1] + 1, 0 ) );
  45. bScore.push_back( make_pair( bS[m - 1] + 1, 0 ) );
  46. aSize = aScore.size();
  47. bSize = bScore.size();
  48. /*
  49. for( i = 0; i < aSize; i++ ) {
  50. printf( "%d.%d", aScore[i].first, aScore[i].second );
  51. }
  52. printf( "\n" );
  53. for( i = 0; i < bSize; i++ ) {
  54. printf( "%d.%d", bScore[i].first, bScore[i].second );
  55. }
  56. printf( "\n" );
  57. */
  58. ia = 0;
  59. ib = 0;
  60. xa = 0;
  61. xb = 0;
  62. res = -200000005;
  63. while( true ) {
  64. score_a = ( n - xa ) * 3 + xa * 2;
  65. score_b = ( m - xb ) * 3 + xb * 2;
  66. if( score_a - score_b > res ) {
  67. res_a = score_a;
  68. res_b = score_b;
  69. res = score_a - score_b;
  70. }
  71. if( (ia == aSize - 1) && (ib < bSize - 1) ) {
  72. ib++;
  73. xb += bScore[ib - 1].second;
  74. } else if( (ia < aSize - 1) && (ib == bSize - 1) ) {
  75. ia++;
  76. xa += aScore[ia - 1].second;
  77. } else if( (ia == aSize - 1) && (ib == bSize - 1) ) {
  78. break;
  79. } else if( aScore[ia].first == bScore[ib].first ) {
  80. ia++;
  81. ib++;
  82. xa += aScore[ia - 1].second;
  83. xb += bScore[ib - 1].second;
  84. } else if( aScore[ia + 1].first <= bScore[ib].first ) {
  85. ia++;
  86. xa += aScore[ia - 1].second;
  87. } else if( bScore[ib + 1].first <= aScore[ia].first ) {
  88. ib++;
  89. xb += bScore[ib - 1].second;
  90. }
  91. //printf( "%d:%d, %d, %d, %d, %d\n", score_a, score_b, xa, xb, ia, ib );
  92. }
  93. printf( "%d:%d\n", res_a, res_b );
  94. return 0;
  95. }
Success #stdin #stdout 0s 3436KB
stdin
3
1 2 3
2
5 6

stdout
9:6