Biased Standing Problem

Solve a SPOJ problem based on the Greedy approach.

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