Statistics

Problem Statement for "OneFight"

Problem Statement

In some computer game, you are surrounded by monsters, and you are to kill them all. Each monster has some number of life points and damage points, and you also have some number of damage points. Life points represent the amount of life left in a monster. As long as a monster has one or more life points, it remains alive. Damage points represent the number of life points that are taken away from an enemy by a single attack. At every turn, you are attacked by each of the living monsters, and then you attack exactly one of them (at the same turn).

You are given a int[] life, the number of life points that each monster starts out with, a int[] damage, the number of damage points each monster has, and an int yourDamage, the number of damage points you have. The ith elements of life and damage represent the life points and damage points for the ith monster. Return the minimal number of life points you must start out with in order to kill all the monsters. At the end of the fight, you must have one or more life points remaining.

Definition

Class:
OneFight
Method:
monsterKilling
Parameters:
int[], int[], int
Returns:
int
Method signature:
int monsterKilling(int[] life, int[] damage, int yourDamage)
(be sure your method is public)

Constraints

  • life will have between 1 and 10 elements, inclusive.
  • life and damage will have the same number of elements.
  • All elements of life will be between 1 and 100, inclusive.
  • All elements of damage will be between 0 and 100, inclusive.
  • yourDamage will be between 1 and 100, inclusive.

Examples

  1. {3}

    {10}

    2

    Returns: 21

    You must hit the monster twice. You lose 20 life points in the fight. Since you must have at least 1 life point remaining, the answer is 21.

  2. {5,1}

    {5,3}

    3

    Returns: 19

    If you kill the first monster and then the second one, you will lose (3+5) + (3+5) + 3 = 19 life points. If you kill the second monster and then first one, you will lose (3+5) + 5 + 5 = 18 life points. You choose the latter option.

  3. {1,5}

    {3,5}

    3

    Returns: 19

  4. {5,5,5,5,5,5,5,5,5,5}

    {10,20,30,40,50,60,70,80,90,100}

    100

    Returns: 2201

    Kill all the monsters in reverse order from last to first.

  5. {6,34,21,79,31,5,8,23,9,100}

    {1,65,95,32,48,9,3,13,100,4}

    4

    Returns: 6554

  6. {2,3,4}

    {1,1,0}

    3

    Returns: 4

  7. {1,2,3,4,5}

    {0,0,0,2,1}

    1

    Returns: 18

  8. {100,100,100,100,100,100,100,100,100,100}

    {100,100,100,100,100,100,100,100,100,100}

    1

    Returns: 550001

  9. {20,5,21,29,37,84}

    {81,47,22,88,54,19}

    61

    Returns: 844

  10. {40,64,28,81,97,17,49,85,18,29}

    {5,45,96,51,97,97,76,54,16,51}

    9

    Returns: 12917

  11. {16}

    {99}

    27

    Returns: 100

  12. {46,33,20,5}

    {12,0,82,52}

    86

    Returns: 223

  13. {58,2,34,64,100}

    {45,89,63,28,41}

    64

    Returns: 709

  14. {45,71,64,35,46,16,78,19,44,24}

    {35,22,74,74,57,28,63,78,56,98}

    75

    Returns: 2728

  15. {49,26,74,62,82,84}

    {55,35,97,32,40,64}

    89

    Returns: 918

  16. {36,64,15,89,5,67,67,27,6,47}

    {27,35,79,14,50,94,3,30,56,68}

    49

    Returns: 2134

  17. {17,60}

    {91,84}

    75

    Returns: 260

  18. {75,75,37,22,34,20,8,3,7}

    {42,83,35,0,49,95,66,5,21}

    93

    Returns: 1263

  19. {52,62,5,29,63}

    {83,92,69,46,40}

    14

    Returns: 2723

  20. {34,28,63}

    {1,50,11}

    27

    Returns: 163

  21. {77,65,86,59,50,17,71,66,93,38}

    {23,30,78,24,36,95,79,65,68,5}

    39

    Returns: 3893

  22. {68,8,83,29,39,76,42}

    {22,29,56,64,81,45,27}

    44

    Returns: 1319

  23. {7,71,67,87,96,11,93,59,77,95}

    {87,100,72,85,85,43,34,4,61,68}

    52

    Returns: 4756

  24. {22,95,66,8,50,68}

    {94,94,74,23,90,13}

    32

    Returns: 1994

  25. {77,8,56,60,46,5,4,58}

    {93,45,1,39,44,68,87,17}

    100

    Returns: 1233

  26. {51,28,72,24}

    {37,38,28,26}

    36

    Returns: 407

  27. {49,26,69,90,49,17,83,82}

    {49,47,73,43,85,40,10,46}

    73

    Returns: 1586

  28. {52,33,97,59,44}

    {81,74,24,58,37}

    10

    Returns: 3556

  29. {25,2}

    {51,27}

    34

    Returns: 106

  30. {6}

    {3}

    37

    Returns: 4

  31. {83,88,63,91}

    {65,49,32,58}

    30

    Returns: 1486

  32. {28,51,70,58,66,69,89,73,71,43}

    {63,84,37,87,3,41,60,73,59,4}

    35

    Returns: 4275

  33. {32,38,72,71,16,68,90,78,67,45}

    {61,95,61,27,35,64,18,80,59,64}

    77

    Returns: 2760

  34. {74,10,51,79,59,33}

    {31,24,45,75,70,55}

    21

    Returns: 2465

  35. {83,14,7,16,74,38,75,66,28}

    {33,19,100,59,99,34,44,3,77}

    33

    Returns: 2539

  36. {79,52,16,3,61,42}

    {87,74,60,41,60,66}

    78

    Returns: 1436

  37. {12,91,80}

    {6,68,52}

    37

    Returns: 559

  38. {40,63}

    {91,30}

    35

    Returns: 303

  39. {62,30,18,31,9,65}

    {93,88,100,0,31,29}

    55

    Returns: 1007

  40. {66,83,72,61,31}

    {27,53,79,18,21}

    74

    Returns: 559

  41. {67,1,86,20,24,19,31,6}

    {31,31,4,17,31,71,12,19}

    1

    Returns: 11965

  42. {94,59,40,36,6}

    {97,93,61,0,78}

    78

    Returns: 918

  43. {37,88,26}

    {19,5,57}

    93

    Returns: 111

  44. {58,18,79,74,68,7,47}

    {23,81,85,70,72,9,20}

    12

    Returns: 5031

  45. {81,33,31,34,68,21}

    {76,4,37,8,90,80}

    100

    Returns: 691

  46. {60,67,50,100,67,79,39,24}

    {32,95,99,56,64,33,19,14}

    37

    Returns: 2805

  47. {63,89}

    {74,94}

    41

    Returns: 619

  48. {19,70,2}

    {52,87,2}

    6

    Returns: 1635

  49. {68,38,83,5,4,74,99}

    {53,57,19,73,60,61,2}

    32

    Returns: 1660

  50. {98,99,83,4,60,99,44}

    {92,89,23,70,5,94,66}

    52

    Returns: 2133

  51. {87,16,92,9,99}

    {97,64,78,66,15}

    27

    Returns: 1767

  52. {90,10,45,60,3,51,36,36,21,15}

    {40,32,46,51,96,28,42,5,56,94}

    15

    Returns: 3928

  53. {80,6,64,90,95,76,84,81}

    {95,28,30,45,44,4,88,31}

    79

    Returns: 2085

  54. {96,14,33,45,26,16,48}

    {50,10,15,23,20,75,16}

    12

    Returns: 2228

  55. {12,6}

    {87,17}

    7

    Returns: 226

  56. {30,2,15,58,7,69,14,37,35,96}

    {22,77,61,23,40,69,8,67,34,46}

    50

    Returns: 2221

  57. {18,83,17,60,56,4,76,71,12,35}

    {94,22,26,51,95,63,70,98,91,43}

    43

    Returns: 3944

  58. {9,59,78,42,75,52,97,9,18,14}

    {19,44,90,7,13,52,38,100,52,37}

    67

    Returns: 2112

  59. {10, 11 }

    {18, 20 }

    10

    Returns: 79

  60. {3,5,6}

    {3,4,5}

    3

    Returns: 39

  61. {6, 34, 21, 79, 31, 5, 8, 23, 9, 100 }

    {1, 65, 95, 32, 48, 9, 3, 13, 100, 4 }

    4

    Returns: 6554

  62. {5, 1 }

    {5, 3 }

    3

    Returns: 19

  63. {100, 6, 34, 21, 79, 31, 5, 8, 23, 9 }

    {1, 65, 32, 48, 95, 4, 9, 13, 3, 100 }

    4

    Returns: 6646

  64. {12, 15, 99, 13, 98 }

    {1, 1, 1, 90, 1 }

    1

    Returns: 1611

  65. {100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }

    {100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }

    1

    Returns: 550001

  66. {100, 95, 91, 99, 92, 93, 98, 97, 94, 96 }

    {100, 99, 98, 97, 96, 95, 94, 93, 92, 91 }

    1

    Returns: 491152

  67. {1, 99 }

    {1, 2 }

    2

    Returns: 104

  68. {5, 5, 5, 100 }

    {100, 100, 100, 10 }

    5

    Returns: 831

  69. {100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }

    {100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }

    7

    Returns: 82501

  70. {1, 100 }

    {10, 20 }

    100

    Returns: 41

  71. {1, 5, 10 }

    {5, 5, 19 }

    4

    Returns: 108

  72. {8, 15 }

    {1, 2 }

    1

    Returns: 54

  73. {99, 1 }

    {99, 50 }

    99

    Returns: 200


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: