Statistics

Problem Statement for "EvaluatingElections"

Problem Statement

Election day is coming in everyone's favorite country, Absurdistan. The elections consist of three steps.

  1. This week anyone can register a political party.
  2. The country is divided into districts. The next week each party will be able to register a candidate in each of the districts.
  3. After that week there is the election day. Each district contains at least one eligible voter. By law, each of the eligible voters has to vote for one of the candidates who are registered in their district. The candidate who receives the most votes is elected to represent the district in the national parliament. In case of a tie nobody is elected from that district.

A party is considered to win the elections if the number of elected candidates belonging to the party is strictly greater than the total number of elected candidates belonging to all other parties.

You have just founded a new party. It will have a candidate in each of the districts.

You are given a int[] districts containing the number of eligible voters in each district. Compute and return the smallest total number X such that if X people vote for your party you are sure to win the elections.

Definition

Class:
EvaluatingElections
Method:
evaluate
Parameters:
int[]
Returns:
int
Method signature:
int evaluate(int[] districts)
(be sure your method is public)

Constraints

  • districts will contain between 1 and 50 elements, inclusive.
  • Each element in districts will be between 1 and 999, inclusive.

Examples

  1. {47}

    Returns: 24

    You need to win this district, and with 24 votes you can be sure that you'll win it.

  2. {9,9}

    Returns: 14

    Imagine the following scenario in which your party gets a total of 13 votes: In district #1 your party gets all 9 votes, in district #2 you get 4 votes and one of the other parties gets 5. In that case your party would not win the elections. On the other hand, with 14 votes you are sure to win both districts.

  3. {1,1,1,1,1,1}

    Returns: 4

    You need to win more than a half, i.e., at least four of these six districts.

  4. {2,2,2,2,2,2}

    Returns: 7

    Clearly, 6 votes are not enough: for example, if you get one vote in each region, there will be six ties and nobody will get elected. With 7 votes for your party there are several ways how these can be distributed. We can easily check that in each of them you are sure to win the elections. For example, you can get both votes in two of the regions and a single vote in three other regions. In that case, you won in two regions, and you forced a tie in three other regions, leaving at most one region for some other party.

  5. {1,2,3,4,5,6,7,8,9}

    Returns: 36

  6. {1,2,3,4,5,6,7,8,9,10}

    Returns: 45

  7. {1,1,100,100,100,100,200,200}

    Returns: 699

  8. {2}

    Returns: 2

  9. {999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999}

    Returns: 37451

  10. {2,3,9}

    Returns: 12

  11. {1}

    Returns: 1

  12. {3}

    Returns: 2

  13. {4}

    Returns: 3

  14. {5}

    Returns: 3

  15. {6}

    Returns: 4

  16. {1,1}

    Returns: 2

  17. {1,2}

    Returns: 3

  18. {2,2}

    Returns: 3

  19. {1,3}

    Returns: 4

  20. {1,4}

    Returns: 5

  21. {2,3}

    Returns: 4

  22. {2,4}

    Returns: 5

  23. {3,3}

    Returns: 5

  24. {100,100}

    Returns: 150

  25. {1,1,1}

    Returns: 2

  26. {1,2,1}

    Returns: 3

  27. {2,2,1}

    Returns: 4

  28. {2,2,2}

    Returns: 4

  29. {10,100,900}

    Returns: 955

  30. {9,99,999}

    Returns: 1053

  31. {2,8,4}

    Returns: 11

  32. {2,2,2,2}

    Returns: 5

  33. {2,2,2,2,4}

    Returns: 8

  34. {784,451,424,422,224,478,509,380,174,797,340,513,842,233,527,342,654,816,637}

    Returns: 7806

  35. {342,574,20,606,413,479,51,630,802,257,16,925,938,951,764,393,766,414,764,208,959,222,85,526,104,848,53,638,969,214,806,318,461,950,768,200,972,746,171,463}

    Returns: 18330

  36. {877,587,587,325,528,5,500,714,548,688,243,5,508,783,561,659,297,44,70,131,329,621,374,268,3,113,782,295,902}

    Returns: 10838

  37. {159,797,323,629,647,941,75,226}

    Returns: 3404

  38. {528,259,717,920,633,957,712,966,216,812,362,146,472,462,140,743,672,512,232,16,186,721,171,831,641,446,183,483,198,55,610,489,884,396,344,499,368,618,812,211,771,449,289}

    Returns: 18074

  39. {608,405,630,751,288,836}

    Returns: 2866

  40. {207,833,960,574,795,758,220,226,377,782,611,104,239,113,992,880,125,525,252,910,990,977,465,734,680,509,435,545,197,182,271,195,684}

    Returns: 15017

  41. {306,800,550,229,87,361,705,12,950,646,476,108,634,631,758,40,866,162,928,634,9,733,206,47,851,5,281,678}

    Returns: 11519

  42. {5,850,234,102,818,710}

    Returns: 2547

  43. {970,883,981,861,690,899,921,261,940,713,49,823,625,296,539,509,515,77,777,392,643,50,87,597,655,164,658,589,119,161,12,785,985}

    Returns: 15696

  44. {340,239,495,366,223,175,742,595,501,322,702,202,401,324,490,285,495,743,733}

    Returns: 6929

  45. {988,167,357,9,804,778,710,333,285,904,157,764,423,291,946,309,753,275,149,826,693,160,322,31,712,257,850,531,907,887,432,398,179,925,979,787,28,667,801,411,751,530,171,160,824,791,195,77}

    Returns: 21882

  46. {402,916,291,858,177,744,276,83,666,994,734,252,382,332,361,941,219,618,650,4,124,715,171,763,271,894,803,221,92,159,623,592,696,807,813,711,957,371,494,500,907,907,564}

    Returns: 19871

  47. {623,832,648,587}

    Returns: 2085

  48. {706,308,863,44,534,429,236,517,296,109,340,222,819,461,90,581,756,7,743,97,161,833,512,868,79,553,737,474}

    Returns: 10926

  49. {462,751,405,13,986,564,289,81,821,586,608,492,891,660,16,760,735}

    Returns: 7661

  50. {685,636,124,393,187,768,819,678,885,263,907,765,220,73,785,926,609,39,539,855,499,427,844,132,93,204,938,208,492,542,761,849,392,79,556,737,433,489,935,865,116,806,704,513,267,405,624}

    Returns: 21487

  51. {514,741,978,507,516,463,668,292,4,683,561,252,192,468,289,150,562,638,204,267,619}

    Returns: 8017

  52. {554,37,563,840,605,753,466,49,919,769,748,968,920,598,609,205,416,418,538,796,298,350,114,65,555}

    Returns: 11112

  53. {112,137,756,175,659,933,42,651,400,379,607,511,269,969,920,526,58,134,188,651,119,752,562,116,865,117,623,738,667,362,709,637,843,227,70,931,33,309,430}

    Returns: 16080

  54. {272,240,866,829,76,517,397,28,994,152,300,960,227,413,326,405,61,112,891,387,818,926,105,491,729,566,825,633,655,381,376,212,237,915,543,86,31,545}

    Returns: 15510

  55. {621,481,892,56,517,55,270,554,644,428,958,165,384,692,262,800,905,997,729,240,914,644,673,329,185,351,388,379,580,943,364,389,301,32,650,569}

    Returns: 15799

  56. {115,82,103,354,432,318,201,783,301,29,297,862,77,466,949,545,134,548,804,55,966,779,798,187,485,837,530,258,449}

    Returns: 11264

  57. {649,841,274,732,747,772,131,514,126,603,34,777,615,113,677,491,912,976,885,671}

    Returns: 9759

  58. {488,192,100,465,675,216,877,144,816,726,466,114,197,880,757,587,606,525,908,430,700,833}

    Returns: 10025

  59. {436,408,976,135,50,409,925,43,807,345,839,807,858,352,427,754,345,717,627,92,450,188,781}

    Returns: 10149

  60. {643,628,250,509,52,71,331,627,189}

    Returns: 2852

  61. {884,856,651,846,406,868,514,843,722,263,345,993,415,18,681,353,489,592,315,508,384,265,486,816,824,681,175,45,614,992,624,155,587,690,622,890,603,282}

    Returns: 17986

  62. {8,463,544,89,116}

    Returns: 1113

  63. {106,162,643,677,634,244,378,726,542,396,911,340,161,306,933,894}

    Returns: 7000

  64. {217,94,826,452}

    Returns: 1433

  65. {956,370,475,824,964}

    Returns: 2754

  66. {215,999,802,614,496,310,412,702,581,889,9,879,303,722,870,281,201,6,152,51,412,277,226,463,763,881,537,217,799,844,161,846,376,543,455,639,962}

    Returns: 16372

  67. {933,497,260,225,363,437,380,60,771,867,911,537,499,737,896,717,179,738,743,98,575,116,194,618,749,107,131,385,931,382,470,450,646,910,727,377}

    Returns: 16048

  68. {35,939,53,724,844,494,499,281,756,433,831,654,244,94,935,454,79,661,27,269,395,919,737,203,671,953,166,173,607,225,239,917,991,754,760}

    Returns: 15825

  69. {667,529,899,457,485,693,360,78,943,354,684,318,204,294,675,902}

    Returns: 7261

  70. {560,483,707,4,449,919,319,20,857,954,394,791,300,495,864,842,657,339,643,429,253,969,172}

    Returns: 10585

  71. {736,153,526,149,949,666,953,897,577,925,140,177,913,403,675,501,282,292,680,550,345}

    Returns: 9724

  72. {224,317,716,50,513,840,361,214,989,134,780,445,384,858,300,84,184,240,762,392,842,824,608,831,759,41,546,815,309,586,226,876}

    Returns: 14085

  73. {108,839,600,999,874,464,969,21,469,986,135,176,564,103,394,487,481,370,78,516,52}

    Returns: 8493

  74. {810,38,572,137,572,680,434,159,496,469,396,150,395,19,727,895,869,148,345,529,379,301,393,269,434,243,815,483,20,173,320,305,937,500}

    Returns: 12505

  75. {379,324,329,867,580,60,556,553,531,685,574,917,645,217,800,781,510,232,13,81,277,577,55,182,422,697,147,620,211,487,285,152}

    Returns: 12053

  76. {847,145,278,672,275,864,336,976,945,370,92,133,812,812,332,364,942,708,794,815,670,89,461,922,177,877,70,858,560,493,549,584,174,827,686,293,468,413,347,379,142,224,451,48,48,973,188,605,524}

    Returns: 21446

  77. {979,908,966,415,608,778,395}

    Returns: 3950

  78. {264,838,54,966,406,355,45,644,429,442,236,895,140,720,902,52,961,716,589,710,654,210,48,681,63,768,911,826,592,453,251,638,109}

    Returns: 14484

  79. {450,419,694,440,780,697,817,935,443,230}

    Returns: 4911

  80. {124,603,746,168,444,682,444,34,534,399,660,792,742,220,282,323,72,292,73,948,615,318,93,666,671,356,523,574,664}

    Returns: 11230

  81. {937,213,975,508,236,551,844,429,789}

    Returns: 4512

  82. {687,376,109,334,329,178,121,580,351,27,125,396,270,344,435,20,373,292,194,66,666}

    Returns: 5401

  83. {510,68,32,911,353,412,389,742,306,457,785,307,666,942,590,184,975,605,848,108,942,776,107,281,774,239,928,981,999,653,49,886,173,407,801,149,194,895,948,366,235,898,517,490,710,131,768}

    Returns: 22240

  84. {166,368,341,479,145,104,845,278,331,250,621,727,529,893,824,351,629,911,632,573,435,337,771,439,155,698,6,47,723,635,462,661,862,916,47,114,493,453,448,823}

    Returns: 16870

  85. {585,567,838,561,875,954}

    Returns: 3523

  86. {932,231,984,621,179,368,576,349,756,712,289,631,379,583,769,818,766,467,928,281,323,852,178,105,974,404,724,28,407,86,110,770,130,640,248,167,370,202,600,44,847,268,79,615,727,69,538}

    Returns: 19461

  87. {359,566,10,521,107,334,75,352,319,983,606,9,660,965,163,512,789,988,451,321,397,81,154,699,492,677,156,187,372,47,229,170}

    Returns: 11384

  88. {706,379,403,929,728,339,323,885,122,849,115,688,866,453,255}

    Returns: 6843

  89. {11,797,599,975,377,166,774,982,299,408,718,127,162,509,350,11,772,565,453,986,313}

    Returns: 9010

  90. {802,511,433,710,261,971,941,241,70,66,378,516,527,93,228,943,610,385,990,241,565,146,467,457,432,9,611,91,553,257,735}

    Returns: 12337

  91. {495,576,330,375,736,935,86,730,817,163,403,761,359}

    Returns: 5658

  92. {136,517,266,768,442,768,92,719,60,162,298,53,568,984,358,652,453,778,9,978,944,32,172,154,925,678,224,179,665,550,437,775,481,314,529,907,471,390,783,703,449,692,688,182}

    Returns: 18701

  93. {414,845,784,78,616,901,324,382,106,422,996,911,992,2,330,195,188,186,736,932,467,339,387,280,629,211,590}

    Returns: 11522

  94. {921,623,76,239,341,63,171,981,160,145,777,750,464,803,364,656,307,525,656,811,286,461,955,687,69,973,914,215,326,635,867,876,911,635,398,982,755,400}

    Returns: 18349

  95. {177,753,388,78,80,661,425,105,329,79,664,480,33,693,459,215,350,961,13,414,252,670,183}

    Returns: 7509

  96. {220,458,506,766,133,846,728,697,693,66,657,274,675,747,140,789,681,749,102,25,614,124,800,532,810,346,606,171,855,818,960,828,192,316,293,578,892,610,13,712,108,576,272,612,194}

    Returns: 19643

  97. {345,250,465,248,144,451,598,611,577,803,899,443,824,431,311,96,310,371,33,467,301,138,276,560,269,301,618,982,499}

    Returns: 10700

  98. {802,934,382,533,818,967,984,405,31,762,848,410,162,932,225,543,415,223,802,78,445,577,380,937}

    Returns: 11743

  99. {220,677,157,204,214,347,876,761,92,302,855,908,125,580,861,782,92,397,387,61,856,962,929,845}

    Returns: 11183

  100. {343,243,813,296,300,614,20,117,87,689,80,753,283,878,40,322,805,168,466,60,941,338,654,641,789,853,738,754,573,336,996,119,413}

    Returns: 13728

  101. {440,18,466,28,262,798,424,869,566,632,684,817,290,857,412,826,329}

    Returns: 7377

  102. {968,278,113,538,798,945,575,199,381,952,775,946,604,892,746,377,13,934,682,924,580,101,213,634,387,259,704,636,501,381}

    Returns: 14580

  103. {925,19,378,137,480,853,911,569,860,205,329,972,539,861,546,932,567,366,287,976,239,498,91,734,305,156,703,610,758,314,187,256,921,774,170,368,641,76,850,869,627,998}

    Returns: 19869

  104. {8,10,12}

    Returns: 21

    With 21 votes for your party you are almost sure to win in at least two regions, and thereby to win the elections. The only case when this does not happen is the case when you get all 12 votes in the largest region and half of the votes in each of the other two. But in this case you won one region and no opponent can win any other region, which still means you win the elections.

  105. {10, 10, 5, 4, 1 }

    Returns: 25


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: