#d11204. 选元素(数据加强版)
选元素(数据加强版)
Selecting Elements (Hard Version)
Problem Description
You are given an integer sequence of length .
Choose exactly elements from it, subject to:
- Every contiguous subsequence of length in the original sequence contains at least one chosen element.
- Under condition 1, the sum of the chosen elements should be as large as possible.
Output the maximum possible sum.
Input Format
The first line contains three integers .
The second line contains integers .
Output Format
If the requirement cannot be satisfied, output .
Otherwise, output one integer: the maximum possible sum of the chosen elements.
Sample Input 1
5 2 3
5 1 3 10 1
Sample Output 1
18
Sample Input 2
6 1 5
10 30 30 70 10 10
Sample Output 2
-1
Sample Input 3
4 3 1
1 100 1 1
Sample Output 3
100
Constraints
For all test cases, and .