MostLikely
SRM 336 · 2007-01-25 · by dgoodman
Problem Statement
Given a
Constraints
- scores will contain between 1 and 50 elements, inclusive.
- Each element of scores will be between 0 and 1,000,000,000, inclusive.
- low will be between 0 and 1,000,000,000, inclusive.
- high will be between low and 1,000,000,000, inclusive.
{3,12,4}
8
8
Returns: 2
It is certain that only the 12 will beat us, giving us a rank of 2.
{3,4,5}
3
7
Returns: 1
Our score is equally likely to be 3 or 4 or 5 or 6 or 7. One of those scores (the 3) gives us a rank of 3. Similarly, one of those scores gives us a rank of 2. And the remaining 3 scores all give us a rank of 1 which is thus the most likely.
{3,4,5}
2
5
Returns: -1
Each of our possible scores gives us a different rank, so all those ranks are tied for most likely.
{121,120,119}
120
120
Returns: 2
{5}
1
1
Returns: 2
Submissions are judged against all 102 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MostLikely with a public method int likelyRank(vector<int> sc, int low, int high) · 102 test cases · 2 s / 256 MB per case