5. In a football tournament, 7 teams competed. Each pair of teams played one match against each other. In the case of a win, the winning team gets 5 points, while the losing team gets no points. In the case of a draw, each of the two teams gets 2 points. It is known that the total number of points earned by all teams in the tournament is 90, and the team with the most points earned 24 points.

What is the maximum possible number of points that the team which was second in terms of points could have earned?
5. The total number of matches is equal to the number of unordered pairs of teams, which is $\frac{7 \cdot 6}{2}=21$.

Let $x$ be the number of matches that ended in a draw.

Then the total number of points is $x \cdot 4 + (21 - x) \cdot 5$. Therefore, we have

$$
x \cdot 4 + (21 - x) \cdot 5 = 90
$$

or

$$
105 - x = 90
$$

so $x = 15$. Thus, 15 matches ended in a draw, and $21 - 15 = 6$ matches ended with a win for one of the teams.

Each team played 6 matches (one with each of the other teams).

The team that scored the most points has 24 points, which means they achieved 4 wins and 2 draws $(4 \cdot 5 + 2 \cdot 2 + 0 \cdot 0 = 24)$.

This means that all other teams together achieved 2 wins, and the highest number of points that any of these teams could have achieved is $2 \cdot 5 + 4 \cdot 2 + 0 \cdot 0 = 18$ points.

(This is possible if the second-placed team played a draw with the first-placed team, won against two of the remaining five teams, and played a draw with the other three teams. All mutual results among the lower-placed teams were draws in this case.)