TopCoder problem "Packhorses" used in SRM 179 (Division II Level Two)



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

0)
    
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.
1)
    
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.
2)
    
20
15
7
Returns: 20
3)
    
1
3
1
Returns: 2

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=2259

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4715&pm=2259

Writer:

dgoodman

Testers:

lbackstrom , brett1479

Problem categories:

Brute Force