시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 256 MB | 21 | 7 | 7 | 43.750% |
There are $N$ houses numbered 1 through $N$. The distance between the house $i$ and the house $j$ is $|i - j|$.
You want to assign $M$ families to these houses. There are $P_i$ people in the $i$-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 $M$ 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.
$N$ $M$
$P_1$
$P_2$
$\vdots$
$P_M$
Print the answer in a single line.
4 3 1 1 2
11
10 10 3 1 4 1 5 9 2 6 5 3
2998
20 10 2 7 1 8 2 8 1 8 2 8
9852
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 $1$, the second family should go to the house $2$, and the third family shuold go to the house $4$.
The distance of residents is $11$.