Problem Statement
You are opening a robotic coffeehouse ("Untouched by human hands!" will be your motto). Your customers can order regular or decaffeinated coffee by the ounce. The machinery processes two orders at once: one order of regular and one order of decaffeinated. Upon receiving the orders, the machinery measures and pours the two drinks into serving cups. Your task is to calculate how many seconds the customers will have to wait for their drinks.
The machinery includes measuring cups of several sizes, but not enough sizes to directly measure all the drink sizes on the menu. Instead, the machinery may measure each of the drinks in several steps. For example, to fulfill an order of 1 ounce of decaffeinated coffee using measuring cups that hold 4, 6, and 9 ounces, respectively, the machinery might follow these steps:
- Pour 4 ounces of coffee from the reservoir into the 4-ounce cup.
- Pour 4 ounces of coffee from the 4-ounce cup into the 9-ounce cup.
- Pour 6 ounces of coffee from the reservoir into the 6-ounce cup.
- Pour 5 ounces of coffee from the 6-ounce cup into the 9-ounce cup, filling the 9-ounce cup to capacity and leaving 1 ounce in the 6-ounce cup.
- Pour the remaining ounce from the 6-ounce cup into the serving cup.
A single pouring action can pour coffee from the reservoir to a measuring cup, from a measuring cup to another measuring cup, from a measuring cup to the reservoir, or from a measuring cup to the serving cup. No measuring cup, serving cup, or reservoir may be involved in more than one pouring action simultaneously. For example, you cannot pour coffee from two different measuring cups into the same reservoir at the same time. A pouring action ends when the source cup is empty or when the destination cup is filled to capacity, whichever comes first. The reservoir is large enough that you can neither empty it nor fill it to capacity. A serving cup has more capacity than needed by the order (to leave room for cream), but you cannot pour coffee out of a serving cup, so you must be careful not to pour more coffee into the serving cup than was ordered.
The system handles regular and decaffeinated coffee simultaneously. There are separate reservoirs and serving cups for the two kinds of coffee, but they both use the same measuring cups. Naturally, however, no measuring cup is permitted to hold both kinds of coffee at the same time. Similarly, regular coffee may not be poured into the decaffeinated reservoir or serving cup, and vice versa.
You will be given the sizes of the measuring cups in a
Definition
- Class:
- Decaffeinated
- Method:
- wait
- Parameters:
- int[], int, int
- Returns:
- int
- Method signature:
- int wait(int[] cups, int regular, int decaf)
- (be sure your method is public)
Notes
- You may not pour coffee on the floor.
Constraints
- cups contains between 1 and 3 elements, inclusive.
- Each element of cups is between 1 and 12, inclusive.
- regular and decaf are both between 1 and 16, inclusive.
Examples
{ 4, 9, 12 }
16
4
Returns: 4
{ 1 }
5
6
Returns: 22
Pouring 1 ounce of coffee first from the reservoir into the measuring cup, and then from the measuring cup into the serving cup, takes 2 seconds. Repeat this process a total of 11 times for a total of 22 seconds.
{ 1, 1 }
5
6
Returns: 12
The same as the previous example, but now you can use two measuring cups simultaneously.
{ 3, 6, 12}
9
13
Returns: -1
{1,3,5}
9
11
Returns: 6
{7,8,9}
4
5
Returns: 10
{ 10, 11, 12 }
8
7
Returns: 11
{ 7,8,9 }
6
2
Returns: 6
{12,5,1}
16
7
Returns: 6
{4,9,7}
4
1
Returns: 5
{12,7,10}
15
10
Returns: 4
{ 11, 12, 11}
6
6
Returns: 31
{ 12,11,11 }
7
8
Returns: 22
{ 2 }
12
10
Returns: 22
{ 3 }
8
9
Returns: -1
{ 7 }
5
7
Returns: -1
{ 7,12,12 }
6
6
Returns: 25
{ 1 }
16
16
Returns: 64
{ 1, 1 }
16
16
Returns: 32
{1,1}
14
16
Returns: 31
{1,1}
16
1
Returns: 18
{ 4,9}
7
11
Returns: 19
{1,1,1}
15
10
Returns: 18
{2,2,2}
11
16
Returns: -1
{1,1,12}
11
13
Returns: 5
{2,2,2}
14
16
Returns: 11
{7,8,11}
5
9
Returns: 8
{11,12}
10
9
Returns: 14
{5}
5
15
Returns: 8
{3,7}
16
15
Returns: 11
{8,2,11}
15
1
Returns: 6
{3,1,6}
13
10
Returns: 6
{ 5,5,9 }
12
13
Returns: 11
{ 6,6,9 }
10
1
Returns: -1
{12,12,10}
16
4
Returns: 9
{6,6,6}
12
12
Returns: 4
{5,3,8}
3
8
Returns: 2
{10,7}
7
10
Returns: 2