Problem Statement
sizes = {25,50,60,120} maximum = 130 Your method will return 120 since all other combinations of components either produce less code, or are greater than the 130 limit.If no software can be built return -1(see last example). Create a class CodeBloat that contains the method biggest, which takes an int[] sizes, and an int maximum and returns an int that represents the biggest the software could be (less than or equal to maximum).
Definition
- Class:
- CodeBloat
- Method:
- biggest
- Parameters:
- int[], int
- Returns:
- int
- Method signature:
- int biggest(int[] sizes, int maximum)
- (be sure your method is public)
Notes
- If no software can be built return -1
Constraints
- sizes must contain between 1 and 20 elements inclusive
- Each element of sizes must be between 1 and 10000 inclusive
- maximum must be between 1 and 1000000 inclusive
Examples
{25,50,60,120}
130
Returns: 120
This is the example from above.
{1,2,3,4,5}
15
Returns: 15
All of the code can be used.
{20,40,45,60,60}
86
Returns: 85
Using 40 and 45 will produce the largest amount of code.
{10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}
1000000
Returns: 200000
{89,73,20,5,5,10000,900}
995
Returns: 994
{122}
1
Returns: -1
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}
193
Returns: 193
{1,5,15,25,30,50}
60
Returns: 60
{10000,9500,9000,8500,8750,10000,10000,10000}
1000000
Returns: 75750
{10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}
1
Returns: -1
{10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}
57000
Returns: 50000
{100,200,300}
42
Returns: -1
{1000,900,800,700,600,600,700,800,900,1000}
3200
Returns: 3200
{100,500,1000,10000}
10555
Returns: 10500
{100,500,1000,10000}
10500
Returns: 10500
{100,500,1000,10000}
10499
Returns: 10100