#P3361. Dormitory Distance Sum
Dormitory Distance Sum
Dormitory Distance Sum
Cool has figured out the layout of the girls' dormitory. The dormitory is composed of many buildings, which can be abstracted as a \(20\times20\) grid. Each girl is positioned at a real coordinate \((x,y)\). A girl \((x,y)\) is said to be in building \((i,j)\) if and only if \(i\le x < i+1\) and \(j\le y < j+1\), where \(i,j\in\mathbb{Z}\).
For any two girls, a distance is defined between them if and only if the building of one is strictly located to the bottom-left of the other; that is, if for two girls with building coordinates \((i_1,j_1)\) and \((i_2,j_2)\), either \(i_1 < i_2\) and \(j_1 < j_2\) or \(i_2 < i_1\) and \(j_2 < j_1\). When the condition holds, the distance is the Manhattan distance between their coordinates, i.e., \[ |x_1-x_2|+|y_1-y_2| \] Cool wants to compute the sum of all such distances among the given \(n\) girls.
inputFormat
The first line contains a single integer \(n\) indicating the number of girls. Each of the next \(n\) lines contains two real numbers \(x\) and \(y\), representing the coordinates of a girl.
outputFormat
Output a single real number—the sum of Manhattan distances for every pair of girls that satisfies the condition. The answer will be considered correct if its absolute or relative error does not exceed \(10^{-6}\).
sample
3
0.5 0.5
1.5 1.5
2.5 2.5
8.000000
</p>