시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
4 초 512 MB 0 0 0 0.000%

문제

You are given an array a of length n and an integer k. You need to find the optimal way to divide the given array into several continuous subarrays with lengths no more than k, to maximize your profit. The profit for one subarray is the sum of its elements multiplied by the mex value of this subarray. You total profit is the sum of profits for all subarrays.

We define the value of mex of a set of non-negative integers as the smallest non-negative integer which doesn’t belong to this set. For example: mex (0, 1, 3) = 2.

입력

The first line contains two integers: n (2 ≤ n ≤ 200 000), the length of the array, and k (1 ≤ k ≤ n), upper bound for the subarray length.

The second line contains n integers, the elements of the array: the i-th integer is ai, 0 ≤ ai ≤ n.

출력

Print a single non-negative integer: the maximum possible profit that can be achieved by dividing the given array into subarrays with lengths no more than k.

예제 입력 1

5 3
3 4 0 0 3

예제 출력 1

10

예제 입력 2

8 4
0 1 2 0 3 1 4 1

예제 출력 2

26

예제 입력 3

10 5
0 2 0 1 2 1 0 2 2 1

예제 출력 3

33