Sorting Proximity (proximity)

5 teams scored 240 points on this task, for a maximum score of 100, an average score of 48 and a median score of 35.

Highlights

  1. U. Dini, Pisa is the institute with the most points (100).
  2. Toscana is the region with the most points (100).

Statement

As a New Year’s resolution, our heroes want everything around them to be clean and perfectly arranged. Thus, they now want to apply their new ideals on their daily work, namely handling the various data structures they are using. This time around, they got an array V_i of length N and they define the sorting proximity of the array as the number of swaps which have to be done in order to sort the array, if we use the bubble sort algorithm. Namely, as long as the array is not sorted yet, the bubble sort algorithm iterates through the array and every time two adjacent values are wrongly placed relative to one another, they are swapped. The sorting proximity is the number of times this happens during the algorithm. For example, if we have the array [4, 2, 3, 5, 1], the sorting proximity of the array is 6, corresponding to the following 6 swaps...