CodeBloat
SRM 113 · 2002-09-10 · by brett1479
SRM 113 · 2002-09-10 · by brett1479
Problem Statement
Problem Statement
You are the project manager for your company's largest software development
project. You know that the best software has the most code, but there is a limit. Use too much code
and your supervisor will say there is bloated code. Given
a list of the sizes of various components you could include in the software,
and the maximum amount of code you are allowed to have, determine the biggest
size the sofware can be (your software must be less than or equal to the
maximum). For example:
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).
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
0)
{25,50,60,120}
130
Returns: 120
This is the example from above.
1)
{1,2,3,4,5}
15
Returns: 15
All of the code can be used.
2)
{20,40,45,60,60}
86
Returns: 85
Using 40 and 45 will produce the largest amount of code.
3)
{10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}
1000000
Returns: 200000
4)
{89,73,20,5,5,10000,900}
995
Returns: 994
Submissions are judged against all 16 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class CodeBloat with a public method int biggest(vector<int> sizes, int maximum) · 16 test cases · 2 s / 256 MB per case