TopcoderArchiveVisit Topcoder
SRM17 Jan 2004
SRM 179

Packhorses

Problem statement, definition, constraints, and public examples.

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. 1
    3
    1
    Returns: 2
Back to all problems