407769: GYM102891 F Alarm Clocks

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Alarm Clockstime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard output

You are given two arrays $$$a$$$ and $$$b$$$ of length $$$n$$$. Initially $$$a_i = 5 \cdot 10^5 + 1$$$ and $$$1 \leq b_i \leq 5 \cdot 10^5$$$ holds for every $$$i$$$ from $$$1$$$ to $$$n$$$. Additionally, you are given a non-negative integer $$$k$$$ such that $$$2k+1 \leq n$$$.

You can make some operations on the array $$$a$$$. In an operation, you can select two positive integers $$$x,v$$$ such that $$$k+1 \leq x \leq n-k$$$, $$$1 \leq v \leq 5 \cdot 10^5$$$, and set $$$a_i$$$ to $$$\min(a_i,v)$$$ for every $$$i$$$ from $$$x-k$$$ to $$$x+k$$$.

After performing some operations, you hope $$$a_i \leq b_i$$$ holds for every $$$i$$$ from $$$1$$$ to $$$n$$$, but you would like to maximize the sum of all elements in $$$a$$$ at the same time. What is the maximum possible sum you can achieve after performing some operations?

Input

The first line contains two integers $$$n, k$$$ ($$$1 \leq n \leq 3000$$$, $$$k \geq 0$$$, $$$2k+1 \leq n$$$).

The second line contain $$$n$$$ integers $$$b_1, b_2, \cdots, b_n$$$ ($$$1 \leq b_i \leq 5 \cdot 10^5$$$).

Output

Print an integer — The maximum possible sum of all elements in $$$a$$$.

Scoring
  • Subtask 1 (7 points): $$$\forall 1 \leq i < n$$$, $$$a_i \leq a_{i+1}$$$.
  • Subtask 2 (14 points): $$$1 \leq a_i \leq 2$$$.
  • Subtask 3 (16 points): $$$1 \leq n \leq 100$$$.
  • Subtask 4 (24 points): $$$1 \leq n \leq 500$$$.
  • Subtask 5 (39 points): No additional constraints.
ExamplesInput
5 1
3 1 2 5 4
Output
11
Input
1 0
12
Output
12
Input
16 3
10 2 17 26 2 23 31 13 9 21 4 4 12 13 19 10
Output
80

加入题单

上一题 下一题 算法标签: