OnLineRank
SRM 179 · 2004-01-17 · by dgoodman
Problem Statement
Create a class OnLineRank that contains a method calcRanks that is given
k, the number of recent scores to use in each rank calculation, and
Each rank should be calculated based on the preceding k scores. If fewer than k scores have preceded this score, base the calculation on all the preceding scores. (The first proposal is thus guaranteed a rank of 1.)
Constraints
- k will be between 1 and 100 inclusive.
- scores will contain between 1 and 50 elements inclusive.
- Each element of scores will be between 0 and 1000 inclusive.
3
{6,9,8,15,7,12}
Returns: 11
The 6 is the first score and earns a rank of 1. The 9 is compared with the 6, which does not exceed it, so it earns a rank of 1. The 8 is compared with the 6 and 9, and is beaten by the 9, so it earns a rank of 2. The 15 is compared with 6, 9, and 8, and earns a rank of 1. The 7 is compared with 9, 8, and 15, but not with 6, which is not recent. Its rank is 4. The 12 is beaten by the 15, earning a rank of 2. 1+1+2+1+4+2 = 11
80
{3,3,3,3,3,3,3}
Returns: 7
No score is exceeded by even one of its predecessors, so each of the seven scores earns a rank of 1.
1
{9,8,7,6,5,4,3,2,1}
Returns: 17
5
{9,8,7,6,5,4,3,2,1}
Returns: 39
9
{1,5,100,92,5,17,45,92,30,30,1,5,100,92,5,17,45,92,30,30,1,5,100,92,5,17,45,92,30,30,1,5,100,92,5,17,45,92,30,30,1,5,100,92,5,17,45,92,30,30}
Returns: 234
Submissions are judged against all 28 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class OnLineRank with a public method int calcRanks(int k, vector<int> scores) · 28 test cases · 2 s / 256 MB per case