#P16777. [GKS 2020 #H] Rugby
[GKS 2020 #H] Rugby
Problem Description
On a far away planet, rugby is played in the -dimensional Cartesian coordinate system without bounds. The players can occupy integer grid points only and they can move to the neighboring grid points in any of the cardinal directions. Specifically, if a player is currently at the point , then they can move to either of the points , , , or in a single step.
After the game, players are scattered throughout the coordinate system such that any grid point is empty or occupied by or more players. They want to gather for a picture and form a perfect horizontal line of grid points, player per point, all occupied points next to each other. Formally, the players have to move so as to occupy the grid points , , , ..., for some coordinates and . What is the minimum total number of steps the players should make to form a perfect line if they are free to choose the position of the line in the coordinate system and the ordering of players is not important?
Input Format
The first line of the input gives the number of test cases . test cases follow. The first line of each test case gives the number of players . The subsequent lines give the initial coordinates of the players. The -th of these lines contains integers and , which describe the initial position of the -th player ().
Output Format
For each test case, output one line containing Case : , where is the test case number (starting from ) and is the minimum total number of steps that the players need to make in order to form a perfect horizontal line.
2
2
1 1
4 4
3
1 1
1 2
1 3
Case #1: 5
Case #2: 4
Hint
In the st test case, of many optimal solutions is obtained by the nd player moving steps to the left and steps down to the point .
In the nd test case, a perfect line can be formed with a total of steps if the st player moves to the point and the rd player moves to the point .
Limits
Test Set
.
.
.
Test Set
for at most cases.
for the remaining cases.
.
.