Statistics

Problem Statement for "Education"

Problem Statement

Even students who hate math find one calculation very useful -- what is the lowest score I can get on the last test and pull out a certain grade? Let's write a program to help them minimize their education.

We will assume that an average score of 90 or higher is rewarded with an A grade, 80 or higher (but less than 90) is a B, 70 or higher (but less than 80) is a C, 60 or higher (but less than 70) is a D. All test scores are integers between 0 and 100 inclusive and the average is NOT rounded -- for example an average of 89.99 does NOT get you an A.

Create a class Education that contains a method minimize that is given a String desire indicating the desired grade and a int[] tests containing the scores on all but the final test. The method returns the lowest possible test score for the final test that will earn at least the desired grade. If even a perfect score won't get the desired grade, return -1.

The desired grade will be given as a String of length 1, either "A", "B", "C", or "D".

Definition

Class:
Education
Method:
minimize
Parameters:
String, int[]
Returns:
int
Method signature:
int minimize(String desire, int[] tests)
(be sure your method is public)

Constraints

  • desire will be "A", "B", "C", or "D"
  • tests will contain between 0 and 20 elements inclusive.
  • Each element of tests will be between 0 and 100 inclusive.

Examples

  1. "A"

    {0,70}

    Returns: -1

    Even a perfect 100 on the last test will only produce an average score of 56.66 so it is not possible to earn an A.

  2. "D"

    {100,100,100,100,100,100}

    Returns: 0

    Nice scores! Even the worst possible score of 0 will give an average of 85.7 earning a B which satisfies your meager desire.

  3. "B"

    {80,80,80,73}

    Returns: 87

    An 87 added to these scores will just exactly improve your average from 78.25 to 80.

  4. "B"

    {80,80,80,73,79}

    Returns: 88

  5. "A"

    {80}

    Returns: 100

  6. "B"

    {69,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80}

    Returns: 91

  7. "C"

    {69,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80}

    Returns: 0

  8. "C"

    {}

    Returns: 70

  9. "D"

    {100,100,100,100,0,19}

    Returns: 1

  10. "C"

    {100,100,100,100,0,19}

    Returns: 71

  11. "D"

    {100,100,100,100,0,20}

    Returns: 0

  12. "D"

    {100,100,100,100,0,21}

    Returns: 0

  13. "D"

    {0}

    Returns: -1

  14. "C"

    {70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,71}

    Returns: 69

  15. "A"

    {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}

    Returns: 0

  16. "C"

    {82,80,91,70,70,70,70}

    Returns: 27

  17. "D"

    { 61, 61, 61, 61, 61, 61 }

    Returns: 54

  18. "A"

    { 79 }

    Returns: -1

  19. "D"

    { 100, 100, 100, 100, 100, 100 }

    Returns: 0

  20. "D"

    { 100, 100, 100, 100 }

    Returns: 0

  21. "A"

    { 80 }

    Returns: 100

  22. "A"

    { 90 }

    Returns: 90

  23. "A"

    { 90, 90, 90, 94 }

    Returns: 86


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: