Connection Status:
Competition Arena > AssignPoints
SRM 821 · 2022-01-07 · by misof · Sorting
Class Name: AssignPoints
Return Type: int[]
Method Name: assign
Arg Types: (int, vector<int>)
Problem Statement

Problem Statement

N people took part in a competition.

The results of the competition are given in the int[] results. For each competitor you are either given the value -1, or a positive value. The value -1 means that this competitor did not finish the competition. The positive value is the time in seconds the competitor needed to finish. Smaller time is better.

After the competition, the competitors should receive points based on their results. The best competitor should get N points, the second best should get N-1, and so on, all the way down to 1 point for the competitor in last place.

There are two additional rules that you need to handle:

  • If a competitor did not finish the competition, they shouldn't get any points.
  • If multiple competitors are tied for the same position, they should each get the same number of points, and that number of points should be the highest from the amounts assigned to their places. For example, if N=10 and three competitors are tied for second place, instead of 9,8,7 points they get 9 points each. (The next competitor would then still get 6 points, not 8.)

Return a int[] with N elements. Element i of the return value should be the number of points assigned to the competitor whose result is given in results[i].

Constraints

  • N will be between 1 and 50, inclusive.
  • results will contain exactly N elements.
  • Each element of results will be either -1 or between 1 and 10,000, inclusive.
Examples
0)
5
{12, 20, 47, 15, 32}
Returns: {5, 3, 1, 4, 2 }

A simple input: who finished sooner gets more points.

1)
4
{-1, -1, -1, -1}
Returns: {0, 0, 0, 0 }

Nobody finished, so nobody gets any points.

2)
5
{-1, 14, -1, -1, 17}
Returns: {0, 5, 0, 0, 4 }

Only two competitors finished. They get 5 and 4 points, respectively, while everyone else gets a zero.

3)
6
{14, 14, 17, 14, 17, 17}
Returns: {6, 6, 3, 6, 3, 3 }

Three competitors are tied for first place (and get 6 points each) while the other three are tied for fourth place (and get three points each).

4)
5
{28, 12, -1, 9, 12}
Returns: {2, 4, 0, 5, 4 }

Submissions are judged against all 63 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class AssignPoints with a public method vector<int> assign(int N, vector<int> results) · 63 test cases · 2 s / 256 MB per case

Submitting as anonymous