#P6524. 「Wdoi-1」托卡马克

「Wdoi-1」托卡马克

Description

During an experiment, Akong accidentally lost control, causing nn damaged spots to appear on the scorching tokamak. To prevent the power of Yatagarasu from being fully released and affecting the surface world, Satori decides to repair the tokamak.

Akong's tokamak can be abstractly seen as a straight line with Akong as the origin. The coordinates of these damaged spots are x1,x2,,xnx_1,x_2,\ldots ,x_n.

  • Satori does not want to spend too much power, so she will only choose mm spots out of the nn damaged spots to repair.

  • To prevent leakage at the damaged spots, Satori will connect every pair among the chosen mm damaged spots with a channel.

  • The cost of a channel connecting xix_i and xjx_j is xixj\left\vert x_i - x_j \right\vert, i.e., the straight-line distance between the two points. The total cost of a plan is defined as the sum of the costs of all channels.

Satori knows there are many ways to repair mm damaged spots, but now she only wants to know: among all valid plans, which plan has the strictly kk-th largest total cost.

“Strictly kk-th largest” means the kk-th largest plan with no ties.

Since Satori can read minds, you only need to output the total cost of that plan.

If no plan meets the requirement, output -1.

Input Format

The first line contains three integers n,m,kn,m,k, with the same meanings as in the statement.

The second line contains nn integers, the coordinates xix_i of the damaged spots.

Output Format

Output one integer in one line, representing the required total cost.

4 2 2
26 1 21 8 
20
2 2 2
1 5
-1

Hint

[Sample Explanation]

  • For sample 1, there are 66 plans in total:

    • (26,1)(26,1), total cost 2525.

    • (26,21)(26,21), total cost 55.

    • (26,8)(26,8), total cost 1818.

    • (1,21)(1,21), total cost 2020.

    • (1,8)(1,8), total cost 77.

    • (21,8)(21,8), total cost 1313.

    Obviously, the strictly second largest cost is 2020.

  • For sample 2, there is 11 plan in total:

    • (1,5)(1,5), total cost 44.

    Obviously, the strictly second largest cost does not exist, so the answer is -1.


[Constraints]

This problem uses bundled testdata.

  • For 100%100\% of the testdata: 1n,m3×1051 \le n,m \le 3 \times 10 ^ 5, 1k21 \le k \le 2, 0xi1080 \le \left\vert x_i \right\vert \le 10 ^ 8, 2m2 \mid m, mnm \le n.

  • Detailed Constraints:

    Subtask ID nn \le Special Property Score
    11 2020 m4m \le 4 1616
    22 3535 1xi71 \le x_i \le 7 and k=1k = 1 99
    33 1xi71 \le x_i \le 7
    44 100100 k=1k = 1 1616
    55 None
    66 3×1053 \times 10 ^ 5 k=1k = 1 1717
    77 None

Translated by ChatGPT 5