P27497 [AtCoder] Auction
普及+
题目描述

Problem Description

Takahashi is enjoying shopping on an auction site. Currently, there are $ N $ items listed on this auction site, and the price of the $ i $-th item is $ A_i $ yen. On this auction site, you can only buy one item per day, and the price of each item increases by $ 1 $ yen every day. Of course, you can only buy the same item once.

Takahashi wants to buy $ K $ items. Find the minimum amount of money Takahashi needs to buy $ K $ items.

Input Format

The input is given from the standard input in the following format:

$ N $ $ K $ $ A_1 $ $ A_2 $ $ ... $ $ A_N $

Output Format

Output the minimum total amount of money Takahashi needs to buy $ K $ items in one line.

Sample Input and Output

Sample Input #1

3 2
1 3 5

Sample Output #1

5

Sample Input #2

5 3
6 3 2 4 7

Sample Output #2

12

Notes/Hints

Constraints

  • $1 \leq N \leq 10^5$
  • $1 \leq K \leq N$
  • $1 \leq A_i \leq 10^9$

Sample Explanation 1

For example, Takahashi can buy $ 2 $ items for $ 5 $ yen by shopping as follows:
- On the first day, buy the item priced at $ 3 $ yen. At this time, the prices of the remaining items increase by $ 1 $ yen each, leaving items priced at $ 2 $ yen and $ 6 $ yen.
- On the second day, buy the item priced at $ 2 $ yen. The total amount spent at this point is $ 5 $ yen.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 2 1 3 5
样例输出
5