#KEYENCE2021B. Mex Boxes

Mex Boxes

Score : 400400 points

Problem Statement

Snuke has NN balls, each with an integer written on it. The numbers on the balls are a1,a2,,aNa_1, a_2, \ldots, a_N.

He has decided to put these NN balls in KK boxes. Every ball must be in some box, but there may be boxes with zero or multiple balls.

After he put the balls in the boxes, the lid of each box will show an integer. Let xx be the integer shown on a box. xx is the minimum non-negative integer such that the box contains no ball with xx. For example, the lid of an empty box will show 00; the lid of a box with balls 0,1,3,50, 1, 3, 5 will show 22; the lid of a box with balls 1,2,31, 2, 3 will show 00.

Find the maximum possible sum of the integers the lids show.

Constraints

  • All values in input are integers.
  • 1KN3×1051 \leq K \leq N \leq 3 \times 10^{5}
  • 0ai<N0 \leq a_i < N

Input

Input is given from Standard Input in the following format:

NN KK

a1a_1 a2a_2 \cdots aNa_N

Output

Print the maximum possible sum of the integers the lids show.

4 2
0 1 0 2
4
  • An optimal solution is to allocate the sets of balls {0,1,2},{0}\{0,1,2 \},\{0\} to the boxes.
  • In this case, the lids show 3,13, 1, respectively, for a total of 44.
5 2
0 1 1 2 3
4
  • An optimal solution is to allocate the (multi)sets of balls {0,1,1,2,3},{}\{0,1,1,2,3\}, \{\} to the boxes.
  • In this case, the lids show 4,04, 0, respectively, for a total of 44.
  • Note that we may have empty boxes.
20 4
6 2 6 8 4 5 5 8 4 1 7 8 0 3 6 1 1 8 3 0
11