Logo
(追記) (追記ここまで)

18669번 - Yet Another Mex Problem 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 512 MB154466.667%

문제

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

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2019 > Day 9: MEX Foundation Contest J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /