atcoder#ABC149E. [ABC149E] Handshake

[ABC149E] Handshake

Score : 500500 points

Problem Statement

Takahashi has come to a party as a special guest. There are NN ordinary guests at the party. The ii-th ordinary guest has a power of AiA_i.

Takahashi has decided to perform MM handshakes to increase the happiness of the party (let the current happiness be 00). A handshake will be performed as follows:

  • Takahashi chooses one (ordinary) guest xx for his left hand and another guest yy for his right hand (xx and yy can be the same).
  • Then, he shakes the left hand of Guest xx and the right hand of Guest yy simultaneously to increase the happiness by Ax+AyA_x+A_y.

However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold:

  • Assume that, in the kk-th handshake, Takahashi shakes the left hand of Guest xkx_k and the right hand of Guest yky_k. Then, there is no pair p,qp, q (1p<qM)(1 \leq p < q \leq M) such that (xp,yp)=(xq,yq)(x_p,y_p)=(x_q,y_q).

What is the maximum possible happiness after MM handshakes?

Constraints

  • 1N1051 \leq N \leq 10^5
  • 1MN21 \leq M \leq N^2
  • 1Ai1051 \leq A_i \leq 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 ...... ANA_N

Output

Print the maximum possible happiness after MM handshakes.

5 3
10 14 19 34 33
202

Let us say that Takahashi performs the following handshakes:

  • In the first handshake, Takahashi shakes the left hand of Guest 44 and the right hand of Guest 44.
  • In the second handshake, Takahashi shakes the left hand of Guest 44 and the right hand of Guest 55.
  • In the third handshake, Takahashi shakes the left hand of Guest 55 and the right hand of Guest 44.

Then, we will have the happiness of (34+34)+(34+33)+(33+34)=202(34+34)+(34+33)+(33+34)=202.

We cannot achieve the happiness of 203203 or greater, so the answer is 202202.

9 14
1 3 5 110 24 21 34 5 3
1837
9 73
67597 52981 5828 66249 75177 64141 40773 79105 16076
8128170