Under construction

Still being built. Things may change

Contest Score

Interview

Time limit2sMemory limit512 MB

Summary
Simulate reading problems in order but solving the shortest available one first, keeping at most k in memory, and report the total submission time.
Level

Medium4 of 10

Topics
Simulation, Heap, Greedy
Solved
No attempts yet

Problem

You are taking part in a programming contest with n problems. Reading a problem tells you exactly how long it will take you to solve it, and reading costs no time. You can keep the details of at most k problems in your head at once.

Let tit_i be the time it takes to solve the ith problem. Your strategy is this:

  1. Read the first k problems.
  2. Among the problems you have read and not yet solved, pick one with the shortest solving time. If several are tied for shortest, pick any of them.
  3. Solve that problem, then read the next unread problem if one is left.
  4. If unsolved problems remain, go back to step 2.

The submission time of a problem is the time elapsed from the start of the contest until you finish solving it. The penalty time is the sum of the submission times of all problems. Given the order of the problems, compute the penalty time of this strategy.

The answer does not depend on which tied problem you pick in step 2, so it is unique.

Input

The first line contains two integers n and k separated by a space (1≤k≤n≤3001 \le k \le n \le 300).

The ith of the next n lines contains one integer tit_i (1≤ti≤1061 \le t_i \le 10^6).

Output

Print the penalty time as a single integer on one line.

Examples2

  1. Example 1

    Input
    4 3
    1
    3
    2
    1
    
    Expected output
    14
    
  2. Example 2

    Input
    5 1
    3
    1
    4
    1
    5
    
    Expected output
    38