#P2034. 选择数字

    ID: 2782 远端评测题 500ms 128MiB 尝试: 1 已通过: 1 显示难度普及+/提高− 上传者: 标签>动态规划 DP单调队列

选择数字

Problem Description

Given a sequence of nn non-negative integers a1,,ana_1 ,\cdots, a_n. You may choose some of them, but no more than kk consecutive numbers can be chosen. Your task is to maximize the sum of the chosen numbers.

Input Format

The first line contains two integers n,kn,k.

The following nn lines each contain one integer, representing aia_i.

Output Format

Output a single value representing the answer.

5 2
1
2
3
4
5 

12

Hint

For 20%20\% of the testdata, n10n \le 10.

For another 20%20\% of the testdata, k=1k=1.

For 60%60\% of the testdata, n103n \le 10^3.

For 100%100\% of the testdata, 1n1051 \le n \le 10^5, 1kn1 \le k \le n, 0ai1090 \le a_i \le 10^9.

Time limit: 500 ms.

Translated by ChatGPT 5