Editorial for COCI '23 Contest 3 #1 Eurokod


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

To solve this task we will create two arrays, one in which we will store the total number of points of the i-th competitor, and the other in which we will store the number of points that the members of the association have assigned to the i-th competitor.

Let's look at the president's scoring. If the i-th place of his ranking is marked with a_i, then the a_i-th competitor gets n-i+1 points, where n is the total number of competitors.

Let's look at the scoring of the members of the association. In the first subtask, it is true that for each code the number of votes of the members for that code is equal to the number of points they assigned to it. In that case, we add the number of votes of the members for his code to the total number of points of the i-th competitor. Let's move on to the general case, when it is not true that the votes and points of the members of the association match. Let's create an array of pairs (b_i, i), where b_i is the number of votes of the members of the association for the i-th code. Sort that array in ascending order by the number of votes. Now we will assign points to the competitors using that array. Let the pair (b_i, i) be at the j-th place. Then the i-th code is assigned j points by the members of the association.

For example, let the votes of the members of the association be 50 10 20, the array of pairs before sorting is (50, 1) (10, 2) (20, 3), and after sorting (10, 2) (20, 3) (50, 1). Then the second code is assigned 1 point, the third 2 points, and the first 3 points.

Let's now create an array where each element consists of three numbers, the first number is the total number of points of the i-th competitor, the second number is the number of points that the i-th competitor received from the members of the association, and the third number is the code label (i.e. the number i).

Sort that array in descending order by the first number, and if the first numbers are equal, then in descending order by the second number.

The sorted array is also the final ranking of competitors. It only remains to print the ranking of competitors in the appropriate format.


Comments

There are no comments at the moment.