Statistics

Problem Statement for "PrimalUnlicensedCreatures"

Problem Statement

The Primal Grez are ferocious creatures. They constantly fight each other. When a Grez wins a battle against another Grez, the winner captures the loser's essence, thus becoming stronger. More formally:
  • The power level of each Grez is a positive integer.
  • A Grez can only defeat creatures that have a strictly smaller power level.
  • When a Grez of power level X defeats a Grez of power level Y, the first Grez's power level is increased to X + Y/2. Note that Y/2 represents integer division, i.e., the fractional part is discarded. For example, for Y=3 we have Y/2 = 1.
Your goal is to help a Grez that currently has power level equal to int initialLevel battle against a set of other Grez. For each i, Grez number i (0-based index) has a power level equal to grezPower[i]. Your Grez can challenge the other creatures in any order.

You are given the int initialLevel and the int[] grezPower. Return the maximum number of creatures your Grez can defeat, one after another.

Definition

Class:
PrimalUnlicensedCreatures
Method:
maxWins
Parameters:
int, int[]
Returns:
int
Method signature:
int maxWins(int initialLevel, int[] grezPower)
(be sure your method is public)

Constraints

  • initialLevel will be between 1 and 1000, inclusive.
  • grezPower will contain between 1 and 50 elements, inclusive.
  • Each element of grezPower will be between 1 and 1000, inclusive.

Examples

  1. 31

    {10, 20, 30}

    Returns: 3

    It is possible to defeat all the available opponents. For example: Defeat the creature with power level 30. Your creature's power level becomes 31 + 15 = 46. Defeat the creature with power level 10. Your creature's power level becomes 46 + 5 = 51. Defeat the creature with power level 20. Your creature's power level becomes 51 + 10 = 61.

  2. 20

    {24, 5, 6, 38}

    Returns: 3

    It is best to defeat creatures 1 and 2 before facing creature 0. Your creature's power level will be 25 when facing creature 0. It is not possible to defeat creature 3.

  3. 20

    {3, 3, 3, 3, 3, 1, 25 }

    Returns: 6

    It is possible to defeat the 6 weakest creatures. After that your creature's power level will be 25, which is not strong enough to defeat another level 25 creature.

  4. 4

    {3, 13, 6, 4, 9}

    Returns: 5

  5. 7

    {7, 8, 9, 10}

    Returns: 0

    All the available opponents are too strong for your creature to defeat.

  6. 713

    {794,857,149,857,663,49}

    Returns: 6

  7. 423

    {351,891,95,526,387,756,717,415,904,541,543,77,456,912,822,70,167,542,337,38,876,463,765,550,614,580,753,80}

    Returns: 28

  8. 32

    {127,818,146,275,340,651,647,105,211,863,6,613,182,833,127,145,184,402,786,740,82,674,309,872,108,197}

    Returns: 1

  9. 112

    {621,268,33,874,107,876,388,595,386,342,471,488,75,437,53,461,21,323,941,863,77,903,550,272,991,219,118}

    Returns: 27

  10. 653

    {856,647,67,375,507,57,175,577,922,550,389,995,874,738,820,961,492,88,818,269,601,170,543,508,174,875,37,290,670,82,110,593,351,514,619,205,544,637,989,261,677,100,579}

    Returns: 43

  11. 837

    {303,853,78,768,546,385,780,100,455,585,143,792,372,557,360,849,255,304,3,835,546,646,59,811,69,8,499,966,473,423,397,147,232,929,927,209,760,192,74,569,316,926}

    Returns: 42

  12. 498

    {511,664,108,16,595,295,170,252,996,482,217,291,288,153,414,626,334,350,639,827,350,131,837,904,407,913,732,919,87,908,79,533,692,486,935,635,866,711,454,179,728,320,851,78,648,271,435}

    Returns: 47

  13. 719

    {138,2,40,851,164,542,585}

    Returns: 7

  14. 749

    {82,329,918,625,432,433,992}

    Returns: 7

  15. 683

    {295,309,111,475,273,314,509,460,356,159,922,933,735,521}

    Returns: 14

  16. 289

    {576,49,225,196,256,625,676,100,324,100,169,961,4,784,121,289,49,25,9,225,100,25,400,4,16,361,16,81,196,25,1,16,64,361,81,49,324,729,441,81,676,16,361,900,100,81,729,196,81}

    Returns: 49

  17. 256

    {289,1,625,841,64,25,841,484,49,289,169,576,400,484,900,841,225,169,900,484,961}

    Returns: 21

  18. 529

    {16,81,841,144,676,4,400,400,841,289,289,441,4,1,361,144,529,625,256,121,225,64,49,576,256,324,729,169,64}

    Returns: 29

  19. 4

    {576,625,49,256,441,324,625,961,225,729,9,25,9,169,441,4,25,289,196,576,36,361,169,64,441,900,100,169,81,144,9,256,784,729,16,625,784,81,121,49,729,121,841,484,144,4}

    Returns: 0

  20. 16

    {900,64,121,841,121,676,676}

    Returns: 0

  21. 121

    {36,729,625,64,900,625,1,100}

    Returns: 4

  22. 625

    {81,144,361,361,4,961,1,169,484,16,64,25,36,841,9,169,49,225,676,64,784,729,225,196,324,441,324,784,576,64,25,225,961,64,9,100,324,225,25,676,9,169,169}

    Returns: 43

  23. 1

    {81,121,576,144,121,64,256,576,169,400,625,900,576,25,144}

    Returns: 0

  24. 289

    {4,400,256,576,900,729,324,4,841,289,121,529,529,256,36,100}

    Returns: 16

  25. 49

    {361,324,64,64,225,361,4,4,25,256,400,324,400,961,289}

    Returns: 5

  26. 64

    {343,512,343,27,27,27,64,512,343,343,1}

    Returns: 5

  27. 1

    {64,512,8,729,343,216,27,216,1,729,27,729,343,216,512}

    Returns: 0

  28. 64

    {216,343,343,125,64,64,64,27,729,8,216,729,512,512,512,125,1,1,729,125,64,216,27,8,343,64,729,729,64,64,343,216,27}

    Returns: 33

  29. 125

    {27,343,27,27,125,343,8,125,27,729,729,27}

    Returns: 8

  30. 216

    {729,27,125,8,216,1,8,8,8,27,64,512,729,1,343,1,125,343,343,343,512,27,8,8,27,729,216,512,216,729,27,64,1,27,8,1,125,64,216,216,512,27,125,512,64,125}

    Returns: 46

  31. 729

    {27,1,8,1,8,125,512,64,8,125,125,216,27,216,1,512,64,729,343,343,27,27,729,729,8}

    Returns: 25

  32. 64

    {125,27,64,27,64,216,343,512,64,27,64,512,64,1,27,8}

    Returns: 16

  33. 1

    {8,729,729,8,216,64,1,729,125,64,64,8,512,216,343,64,343,729,729,512,216,64,512,729,343,1,27,729,64,343}

    Returns: 0

  34. 216

    {1,8,216,512,216,125,1,125,8,512,64,27,64,729,64,512,125,64,125,216,8,343,27,343}

    Returns: 24

  35. 343

    {1,512,125,64,64,1,8,216,8,1,125,216,512,1,512}

    Returns: 15

  36. 3

    {2, 3, 4, 6, 9, 13, 19, 28, 42, 63, 94, 141, 211, 316, 474, 711}

    Returns: 16

  37. 3

    {2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512}

    Returns: 18

  38. 3

    {2, 2, 2, 5, 5, 5, 11, 11, 11, 26, 26, 26, 65, 65, 65, 161, 161, 161, 401, 401, 401}

    Returns: 21

  39. 7

    {7, 8, 9, 10 }

    Returns: 0

  40. 3

    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }

    Returns: 16

  41. 500

    {10, 20, 30 }

    Returns: 3

  42. 3

    {5, 4, 3, 2 }

    Returns: 4

  43. 6

    {6, 5 }

    Returns: 2

  44. 4

    {3, 13, 6, 4, 9 }

    Returns: 5

  45. 20

    {24, 5, 6, 38 }

    Returns: 3

  46. 3

    {3, 3 }

    Returns: 0

  47. 10

    {10, 10 }

    Returns: 0

  48. 30

    {1, 30 }

    Returns: 1

  49. 2

    {1, 2 }

    Returns: 1

  50. 10

    {999, 999, 999, 888, 899, 910, 920, 930, 940, 950, 960, 960, 777, 456, 678, 987, 654, 345, 456, 456, 2, 456 }

    Returns: 1

  51. 3

    {1, 1, 1, 1, 1, 1, 1, 1 }

    Returns: 8

  52. 1000

    {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: 50

  53. 20

    {37, 24, 6, 6 }

    Returns: 4

  54. 1000

    {999 }

    Returns: 1

  55. 10

    {1, 150, 400 }

    Returns: 1


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: