TopcoderARCHIVE
Archive/Problems/AssignPoints
SRM · Problem 17351

AssignPoints

Problem statement, definition, constraints, and public examples.

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].

Definition

Class:
AssignPoints
Method:
assign
Parameters:
int, int[]
Returns:
int[]
Method signature:
int[] assign(int N, int[] results)
(be sure your method is public)

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

  1. 5
    {12, 20, 47, 15, 32}
    Returns: {5, 3, 1, 4, 2 }
    A simple input: who finished sooner gets more points.
  2. 4
    {-1, -1, -1, -1}
    Returns: {0, 0, 0, 0 }
    Nobody finished, so nobody gets any points.
  3. 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.
  4. 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).
  5. 5
    {28, 12, -1, 9, 12}
    Returns: {2, 4, 0, 5, 4 }
← All problems