House Moving

아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

There are NN houses numbered 1 through NN. The distance between the house ii and the house jj is ij|i - j|.

You want to assign MM families to these houses. There are P_iP\_i people in the ii-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 MM 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.

입력

NN MM
P_1P\_1
P_2P\_2
\vdots
P_MP\_M

출력

Print the answer in a single line.

제한

  • 2N1062 \leq N \leq 10^6
  • 2Mmin(N,1000)2 \leq M \leq \min(N, 1000)
  • 1P_i1001 \leq P\_i \leq 100

힌트

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 11, the second family should go to the house 22, and the third family shuold go to the house 44.

  • The distance between A and B: 11
  • The distance between A and C: 33
  • The distance between A and D: 33
  • The distance between B and C: 22
  • The distance between B and D: 22
  • The distance between C and D: 00

The distance of residents is 1111.