Under construction

Still being built. Things may change

Card merge game

Interview

Time limit1sMemory limit512 MB

Summary
Each merge replaces two chosen cards with their sum; after exactly m merges, minimize the total sum of all cards.
Level

Medium5 of 10

Topics
Greedy, Heap, Simulation, Implementation
Solved
No attempts yet

Problem

You have nn cards with natural numbers. Card ii shows aia_i at the start. One merge follows these steps.

  1. Choose two different cards, card xx and card yy, and compute the sum of the two numbers. (x≠yx \ne y)
  2. Write the computed value on both card xx and card yy.

After mm merges, the score is the sum of the numbers on all nn cards. Choose the cards to merge so the score is as small as possible, and compute the smallest possible score.

Input

The first line contains the number of cards nn (2≤n≤10002 \le n \le 1000) and the number of merges mm (0≤m≤15n0 \le m \le 15n), separated by a space.

The second line contains the nn initial natural numbers a1,a2,…,ana_1, a_2, \dots, a_n, separated by spaces. (1≤ai≤10000001 \le a_i \le 1000000)

Output

Print the smallest possible score on the first line.

Examples2

  1. Example 1

    Input
    3 1
    3 2 6
    
    Expected output
    16
    
  2. Example 2

    Input
    4 2
    4 2 3 1
    
    Expected output
    19