Statistics

Problem Statement for "Packhorses"

Problem Statement

We have p people, x small packs, and y large packs. A packhorse can carry one of the following loads. It is not possible to have a horse carry a mixture of small and large packs.
  • 3 or fewer small packs
  • 2 or fewer large packs
  • a person and 2 or fewer small packs
  • a person and 1 large pack
We need to know the fewest horses that we can use to handle our people and packs. Create a class Packhorse that contains a method horses that is given p, x, and y and returns the smallest number of horses that can carry the load.

Definition

Class:
Packhorses
Method:
horses
Parameters:
int, int, int
Returns:
int
Method signature:
int horses(int p, int x, int y)
(be sure your method is public)

Constraints

  • p will be between 1 and 1000 inclusive.
  • x and y will be between 0 and 1000 inclusive.

Examples

  1. 1

    5

    0

    Returns: 2

    One horse can carry the person and two small packs, and the other can carry the remaining three small packs.

  2. 1

    6

    0

    Returns: 3

    One way to get 3 horses to carry this load is to have each horse take two small packs, with one of the horses also carrying the person.

  3. 20

    15

    7

    Returns: 20

  4. 5

    1

    5

    Returns: 6

  5. 5

    5

    18

    Returns: 13

  6. 1

    3

    1

    Returns: 2

  7. 1

    0

    0

    Returns: 1

  8. 1

    1000

    1000

    Returns: 834

  9. 1

    998

    1000

    Returns: 833

  10. 1000

    1000

    1000

    Returns: 1250

  11. 498

    1000

    1000

    Returns: 1000

  12. 497

    1000

    1000

    Returns: 999

  13. 300

    1

    932

    Returns: 617

  14. 300

    0

    932

    Returns: 616

  15. 30

    3

    722

    Returns: 377

  16. 30

    3

    723

    Returns: 378

  17. 30

    3

    724

    Returns: 378

  18. 1000

    1000

    1000

    Returns: 1250

  19. 2

    3

    0

    Returns: 2

  20. 100

    222

    333

    Returns: 274

  21. 1

    9

    1

    Returns: 4

  22. 2

    5

    1

    Returns: 3

  23. 1

    2

    2

    Returns: 2

  24. 2

    4

    2

    Returns: 3

  25. 969

    1000

    999

    Returns: 1234

  26. 1

    1

    2

    Returns: 2

  27. 2

    5

    3

    Returns: 4

  28. 1

    30

    0

    Returns: 11

  29. 20

    153

    137

    Returns: 127

  30. 20

    13

    19

    Returns: 23

  31. 5

    6

    5

    Returns: 7

  32. 1

    3

    7

    Returns: 5

  33. 30

    60

    50

    Returns: 55

  34. 1

    5

    2

    Returns: 3

  35. 20

    80

    21

    Returns: 44

  36. 5

    10

    4

    Returns: 7

  37. 500

    1000

    5

    Returns: 503


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: