#P2048. [NOI2010] 超级钢琴

    ID: 990 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心2010二叉堆NOI 系列O2优化RMQ前缀和st表,稀疏表

[NOI2010] 超级钢琴

Description

Xiao Z is a well-known pianist. Recently, Dr. C gave Xiao Z a super piano, and Xiao Z hopes to use it to create the most beautiful music in the world.

This super piano can play nn notes, indexed from 11 to nn. The beauty value of the ii-th note is AiA_i, where AiA_i can be positive or negative.

A “super chord” consists of several consecutive notes, with the number of included notes no less than LL and no more than RR. We define the beauty of a super chord as the sum of the beauty values of all notes it contains. Two super chords are considered the same if and only if the sets of notes they contain are identical.

Xiao Z decides to compose a piece consisting of kk super chords. To make the piece more pleasing, the kk super chords must be different. We define the beauty of a piece as the sum of the beauties of all its super chords. Xiao Z wants to know the maximum possible beauty of such a piece.

All testdata satisfy: 1000Ai1000-1000 \leq A_i \leq 1000, 1LRn1 \leq L \leq R \leq n, and it is guaranteed that there exists a valid piece that meets the requirements.

Input Format

The first line contains four positive integers n,k,L,Rn, k, L, R, where nn is the number of notes, kk is the number of super chords in the piece, and LL and RR are the lower and upper bounds on the number of notes a super chord can contain, respectively.

The next nn lines each contain an integer AiA_i, representing the beauty value of each note in increasing index order.

Output Format

Output a single integer, the maximum possible beauty of the piece.

4 3 2 3
3
2
-6
8
11

Hint

Sample Explanation

There are 55 different super chords:

  1. Notes 121 \sim 2, beauty 3+2=53+2=5.
  2. Notes 232 \sim 3, beauty 2+(6)=42+(-6)=-4.
  3. Notes 343 \sim 4, beauty (6)+8=2(-6)+8=2.
  4. Notes 131 \sim 3, beauty 3+2+(6)=13+2+(-6)=-1.
  5. Notes 242 \sim 4, beauty 2+(6)+8=42+(-6)+8=4.

The optimal plan is: the piece consists of chords 1,3,51, 3, 5, with total beauty 5+2+4=115+2+4=11.

Translated by ChatGPT 5