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