Statistics

Problem Statement for "PassingGrade"

Problem Statement

You are studying for the final exam in a tough course, and want to know how many points you need to score on the final to pass the course. You know how many points you earned on each assignment (pointsEarned), how many points were possible on each assignment (pointsPossible), and how many points are possible on the final exam (finalExam). You need to earn a minimum of 65% of the total possible points to pass the course. Assume your score on the final exam will be an integral number of points between 0 and finalExam, inclusive. Return the number of points you need to score on the final to pass the course, or -1 if it is impossible for you to pass the course.

Definition

Class:
PassingGrade
Method:
pointsNeeded
Parameters:
int[], int[], int
Returns:
int
Method signature:
int pointsNeeded(int[] pointsEarned, int[] pointsPossible, int finalExam)
(be sure your method is public)

Constraints

  • pointsEarned contains between 1 and 20 elements, inclusive.
  • pointsPossible contains the same number of elements as pointsEarned.
  • Each element of pointsPossible is between 1 and 1000, inclusive.
  • Element i of pointsEarned is between 0 and element i of pointsPossible, inclusive.
  • finalExam is between 1 and 3000, inclusive.

Examples

  1. {55,77,82,60}

    {100,100,100,100}

    300

    Returns: 181

    If you score 181 points on the final, then you will finish the course with exactly 65% of the possible points.

  2. { 1, 2, 3, 4 }

    { 2, 3, 4, 5 }

    7

    Returns: 4

    If you score 4 points on the final, then you pass with 66.7% of the total possible points, but if you score 3 points on the final, then you fail with 61.9% of the possible points.

  3. { 1, 2, 2, 1 }

    { 9, 9, 9, 9 }

    9

    Returns: -1

    Even if you score 9 points on the final, you still fail with 33.3% of the possible points.

  4. { 7, 8, 7, 6 }

    { 8, 8, 8, 8 }

    9

    Returns: 0

    You will pass even if you score 0 points on the final.

  5. { 17, 23, 50, 200, 19, 56, 83, 91, 77, 9, 0 }

    { 20, 30, 50, 250, 20, 70, 100, 100, 100, 10, 10 }

    400

    Returns: 129

  6. { 0,0,0,0,0,0,0 }

    { 1,1,1,1,1,1,1 }

    3000

    Returns: 1955

  7. { 1000, 1000, 1000, 1000 }

    { 1000, 1000, 1000, 1000 }

    3000

    Returns: 550

  8. { 495 }

    { 513 }

    1678

    Returns: 930

  9. { 239,656 }

    { 356,704 }

    1618

    Returns: 846

  10. { 156,82,91 }

    { 407,929,98 }

    1817

    Returns: 1785

  11. { 299,519,253,56 }

    { 536,596,306,437 }

    69

    Returns: -1

  12. { 842,144,400,277,620 }

    { 868,201,889,282,740 }

    1220

    Returns: 447

  13. { 911,2,571,749,687,48 }

    { 913,376,914,998,702,710 }

    992

    Returns: 676

  14. { 108,282,539,359,542,637,716 }

    { 621,605,696,464,883,708,927 }

    2296

    Returns: 1497

  15. { 27,51,74,14,62,318,284,64 }

    { 36,425,815,167,985,496,371,80 }

    2458

    Returns: -1

  16. { 12,221,49,620,494,256,525,547,718 }

    { 611,297,208,981,787,379,622,749,910 }

    372

    Returns: -1

  17. { 2,692,83,231,922,237,574,84,72,701 }

    { 4,877,114,251,938,279,760,667,541,781 }

    2429

    Returns: 1369

  18. { 131,372,541,343,178,957,208,19,384,666,437 }

    { 167,574,622,454,530,965,284,214,519,789,527 }

    2373

    Returns: 976

  19. { 382,710,805,615,377,255,256,30,70,316,372,173 }

    { 999,947,839,689,491,758,652,156,123,731,455,526 }

    2517

    Returns: 2063

  20. { 366,176,95,403,9,9,21,701,388,29,422,473,444 }

    { 976,276,296,516,33,30,596,786,716,30,620,784,793 }

    670

    Returns: -1

  21. { 408,800,5,306,2,703,311,163,760,742,640,574,301,565 }

    { 949,936,7,404,191,899,964,393,914,805,706,619,529,734 }

    2946

    Returns: 1518

  22. { 26,530,60,18,547,53,529,671,90,140,208,19,329,242,233 }

    { 87,648,609,65,554,150,736,837,368,147,223,438,475,893,349 }

    513

    Returns: -1

  23. { 82,148,470,33,453,305,526,812,203,306,399,319,16,525,18,683 }

    { 94,498,537,639,682,880,658,908,295,321,416,739,40,754,19,744 }

    2064

    Returns: 1390

  24. { 316,606,224,16,172,10,309,36,734,182,24,326,228,28,540,323,217 }

    { 486,909,228,71,280,615,582,39,988,271,590,539,294,654,624,479,315 }

    64

    Returns: -1

  25. { 619,85,356,482,359,210,426,804,789,87,163,21,447,236,755,230,350,626 }

    { 863,100,368,506,701,233,559,925,832,155,165,42,721,285,976,363,941,789 }

    1175

    Returns: 0

  26. { 412,138,146,128,494,57,189,890,383,471,77,5,278,39,251,324,33,193,355 }

    { 619,168,217,325,632,531,300,925,402,792,326,337,543,60,818,399,383,222,384 }

    1090

    Returns: -1

  27. { 1,649,369,878,480,870,12,590,296,553,286,800,472,302,793,104,558,967,38,572 }

    { 10,993,476,966,794,984,35,598,531,573,306,867,500,410,840,294,654,987,413,947 }

    130

    Returns: 0

  28. { 146,82,43,916,151,486,541,68,119,244,109,22,372,171,348,811,216,491,95,326 }

    { 176,91,389,988,430,614,541,708,190,285,630,881,565,264,537,820,287,692,124,410 }

    2969

    Returns: 2428

  29. { 353,88,5,493,324,14,123,133,274,44,587,275,760,605,153,451,18,938,335,133 }

    { 421,88,9,581,407,46,123,403,319,105,696,434,871,785,225,586,107,948,556,775 }

    1986

    Returns: 701

  30. { 134,328,33,211,149,767,394,445,335,527,216,570,421,214,124,140,146,785,229,478 }

    { 569,403,134,410,224,912,632,561,455,683,278,725,478,358,197,551,178,914,698,657 }

    2995

    Returns: 1812

  31. { 78,138,317,64,130,73,435,129,362,82,11,180,373,228,112,744,187,20,744,685 }

    { 123,766,425,106,518,121,704,161,404,115,99,878,592,592,172,778,540,30,866,897 }

    486

    Returns: -1

  32. { 188,12,158,502,621,793,12,28,201,95,887,556,545,55,439,462,224,372,239,1 }

    { 769,236,237,792,987,991,42,39,411,205,963,867,560,61,500,628,656,494,565,17 }

    927

    Returns: 726

  33. { 138,226,370,70,401,345,238,752,681,633,633,104,76,300,314,25,64,240,78,393 }

    { 260,317,572,225,587,366,248,808,838,895,892,357,77,368,495,163,165,368,411,431 }

    2673

    Returns: 1405

  34. { 407,8,61,89,351,76,399,139,79,83,57,343,231,522,706,19,361,0,575,266 }

    { 607,157,64,794,575,85,717,140,480,122,251,557,344,675,939,718,629,111,719,285 }

    691

    Returns: -1

  35. { 564,213,659,95,196,67,54,65,513,125,463,503,535,73,195,520,37,403,548,2 }

    { 864,450,806,384,283,179,100,509,726,138,604,520,758,121,299,525,172,853,722,4 }

    407

    Returns: 296

  36. { 521,46,514,474,327,399,7,216,6,106,558,12,415,599,546,473,117,209,74,487 }

    { 932,319,732,912,413,422,62,335,16,296,673,19,585,642,814,772,697,229,292,558 }

    512

    Returns: -1

  37. { 147,56,535,30,128,98,605,12,509,743,229,677,679,331,337,182,310,38,321,103 }

    { 182,90,899,124,167,101,859,19,544,829,243,848,768,368,454,205,375,371,382,635 }

    2269

    Returns: 906

  38. { 650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650 }

    { 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,998 }

    3000

    Returns: 1949

  39. { 650 }

    { 700 }

    300

    Returns: 0

  40. { 650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650 }

    { 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, 1000,1000,1000,1000,1000,1000,1000,1000,1000,993 }

    3000

    Returns: 1946

  41. {600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600}

    {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}

    2999

    Returns: 2950

  42. {600,600,600,600,600,600,600,600,600,600, 600,600,600,600,600,600,600,600,600,600}

    {1000,1000,1000,1000,1000,1000,1000,1000, 1000,1000,1000,1000,1000,1000,1000,1000, 1000,1000,1000,901}

    3000

    Returns: 2886

  43. { 200, 350 }

    { 200, 700 }

    101

    Returns: 101

  44. { 1, 2, 2, 1 }

    { 9, 9, 9, 9 }

    9

    Returns: -1

  45. { 0 }

    { 1 }

    4

    Returns: 4

  46. { 1 }

    { 1 }

    3000

    Returns: 1950

  47. { 400 }

    { 700 }

    300

    Returns: 250

  48. { 6 }

    { 9 }

    2

    Returns: 2

  49. { 99, 99 }

    { 100, 100 }

    100

    Returns: 0

  50. { 100, 100, 100, 100 }

    { 100, 100, 100, 100 }

    100

    Returns: 0

  51. { 100 }

    { 100 }

    10

    Returns: 0

  52. { 7, 8, 7, 6 }

    { 8, 8, 8, 8 }

    9

    Returns: 0

  53. { 1, 2, 3, 4 }

    { 2, 3, 4, 5 }

    7

    Returns: 4

  54. { 100 }

    { 100 }

    1

    Returns: 0

  55. { 10, 5 }

    { 12, 7 }

    6

    Returns: 2

  56. { 2 }

    { 3 }

    4

    Returns: 3

  57. { 452 }

    { 700 }

    302

    Returns: 200

  58. { 0 }

    { 35 }

    65

    Returns: 65

  59. { 50 }

    { 50 }

    55

    Returns: 19

  60. { 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600 }

    { 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 901 }

    3000

    Returns: 2886

  61. { 1, 2, 3, 4 }

    { 2, 3, 4, 5 }

    8

    Returns: 5

  62. { 4 }

    { 6 }

    10

    Returns: 7


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: