House Moving
시간 제한1초메모리 제한256 MB
크기가 주어진 M개의 가족을 N개의 집에 서로 다르게 배치해 모든 사람 쌍의 거리 합을 최대로 만든다.
문제
There are houses numbered 1 through . The distance between the house and the house is .
You want to assign families to these houses. There are people in the -th family. No two families can be assigned to the same house.
Your objective is to maximize the distance of residents. For each (unordered) pair of two people among the families, compute the distance between their houses. The distance of residents is defined as the sum of these values for all pairs.
Compute the maximum possible value of the distance of residents.
입력
출력
Print the answer in a single line.
제한
힌트
In the Sample 1, let A be the member of the first family, B be the member of the second family, and C, D be the members of the third family.
In the optimal assignment, the first family shuold go to the house , the second family should go to the house , and the third family shuold go to the house .
- The distance between A and B:
- The distance between A and C:
- The distance between A and D:
- The distance between B and C:
- The distance between B and D:
- The distance between C and D:
The distance of residents is .