Search⌘ K

Biased Standing Problem

Explore how to apply greedy algorithms to optimize rankings by minimizing total badness, which measures the distance between each team's preferred and actual placement. Understand the solution through sorting and calculating absolute differences, and implement it effectively in C++.

We'll cover the following...

Problem statement

In a competition, each team is able to enter its preferred place in the rank list. Suppose that we already have a rank list. For each team, compute the distance between its preferred place and its actual place in the rank-list. The sum of these distances will be called the badness of this rank list. Given team names and their preferred placements in the rank list, find one rank list with minimal possible badness and print the badness.

Let us take an example to see what the inputs will be and how the result is defined.

We have the following input, where the string is the team name and the integer value defines the preferred placement of the team in the rank-list.

  • noobz 1
  • llamas 2
  • Winn3rz 2
...