Problem Statement
A big band is going to perform in your arcade, and since you are the head technician you are responsible for helping them to set up their equipment. The place where they can set up has five outlets, each protected by a circuit breaker that is set to a certain amperage called its amperage rating. Amperage is a term for the speed of electricity that passes through a point, and is measured in amps. Anything that gets plugged into an outlet pulls a specific number of amps, unless the amperage supplied would be greater than the circuit breaker's rating, which would cause the circuit breaker to trip and the flow of electricity to stop. When multiple pieces of equipment are plugged into the same outlet, their amperage is cumulative; a guitar pulling 1 amp and a speaker pulling 8 amps will pull a total of 9 amps when they're plugged into the same outlet. The band has ten pieces of equipment to plug in, each piece of equipment needing a specified number of amps in order to operate. The total potential amperage of the band is the sum of the amperage ratings of the outlets that they use for their equipment. You have to come up with a way for them to plug into the outlets so that they don't trip any of the breakers, and if possible to minimize their total potential amperage.
You will be given a int[] of the amperage ratings of the outlets. You will also be given a int[] of the number of amps that each piece of equipment will pull from an outlet. It is unacceptable for the amount of amperage pulled from an outlet to exceed the rating for the breaker. From all acceptable ways to plug into the outlets, your program will return the minimum total potential amperage possible. If there's no way for the band to plug into the outlets without tripping a breaker, return -1.
Definition
- Class:
- CircuitBreakers
- Method:
- optimalAmperage
- Parameters:
- int[], int[]
- Returns:
- int
- Method signature:
- int optimalAmperage(int[] outlets, int[] equipment)
- (be sure your method is public)
Constraints
- outlets will contain exactly 5 elements.
- Each element of outlets will be between 1 and 100, inclusive.
- equipment will contain exactly 10 elements.
- Each element of equipment will be between 1 and 100, inclusive.
Examples
{10,10,10,10,10}{5,5,5,5,5,5,5,5,5,5}Returns: 50
Each outlet can take two pieces of equipment and take the entire load. Sum of the amperage from all outlets are 10 amps + 10 amps + 10 amps + 10 amps + 10 amps or 50 amps.{10,10,10,10,10}{5,5,5,5,5,5,5,5,5,6}Returns: -1
The total amperage pull from all the equipment is 51 amps. The outlets can only give 50 amps total before something trips. There's no way for the band to use all their equipment, so return -1.{10,9,8,7,6}{1,1,1,1,1,1,1,1,1,1}Returns: 10
You could plug 6 pieces of equipment into the 6 amp outlet, and 4 more into the 7 amp outlet, but that would give a total potential amperage of 13 amps (6 amps + 7 amps), and that's not the minimum. Rather, by plugging all ten pieces of equipment into the 10-amp outlet, you get a total potential amperage of 10 amps which is the minimum.{26,24,30,10,46}{13,17,13,12,12,23,23,6,6,1}Returns: 126
{50,40,30,20,5}{10,9,8,7,6,5,4,3,2,1}Returns: 55
{5,5,5,5,5}{1,1,1,1,1,1,1,1,1,6}Returns: -1
There are more than enough amps for all the equipment, however one of your pieces of equipment can't be plugged into any outlet without tripping a breaker.{5,5,5,5,5}{3,4,3,4,3,4,1,1,1,1}Returns: -1
Similar situation. You can provide 25 amps. The equipment needs 25 amps. But there are 6 pieces of equipment with >=3 amps needed to power them, and because of the pigeonhole principle you'd be required to plug two of these into the same outlet which would require >5 amps and that would throw a breaker.{5,5,5,5,6}{3,4,3,4,3,4,2,1,1,1}Returns: 26