Connection Status:
Competition Arena > Packhorses
SRM 179 · 2004-01-17 · by dgoodman · Brute Force
Class Name: Packhorses
Return Type: int
Method Name: horses
Arg Types: (int, int, int)
Problem Statement

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.

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)
5
1
5
Returns: 6
4)
5
5
18
Returns: 13

Submissions are judged against all 37 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Packhorses with a public method int horses(int p, int x, int y) · 37 test cases · 2 s / 256 MB per case

Submitting as anonymous