Super piano
[Problem description]
Little Z is a famous pianist. Recently, Dr. C gave little Z a super piano. Little Z hopes to use it to create the most wonderful music in the world.
This super piano can play n notes numbered 1 to n. The beauty of the I-th note is Ai, where AI can be positive or negative.
A "superchord" is composed of several consecutive numbered notes, containing no less than l and no more than R. We define the beauty of a super chord as the sum of the beauty of all its notes. Two superchords are considered to be the same if and only if the set of notes contained by these two superchords is the same.
Little Z decided to create a piece of music consisting of K super chords. To make the music more appealing, little Z asked the piece to be composed of k different super chords. We define the beauty of a piece of music as the sum of the beauty of all its super chords. Z wants to know the maximum value of the music he can create.
[Input format]
The input file name is piano. In.
The first line of the input file contains four positive integers, n, k, l, and R. Where N is the number of notes, k is the number of super chords contained in the music, and l and R are the lower limit and upper limit of the number of notes contained in the super chord, respectively.
In the next n rows, each line contains an integer AI, indicating the beauty of each note from small to large by number.
[Output format]
The output file is piano. Out.
The output file has only one integer, indicating the maximum music beauty.
[Example input]
4 3 2 3
3
2
-6
8
[Sample output]
11
[Example]
There are 5 different super chords:
- Note 1 ~ 2, the beauty is 3 + 2 = 5
- Note 2 ~ 3, the beauty is 2 + (-6) =-4
- Note 3 ~ 4, The beauty is (-6) + 8 = 2
- Note 1 ~ 3, the beauty is 3 + 2 + (-6) =-1
- Note 2 ~ 4, The beauty is 2 + (-6) + 8 = 4
The optimal solution is: Music consists of chord 1, Chord 3, and chord 5. The beauty is 5 + 2 + 4 = 11.
[Operation time limit]
2 seconds.
[Operation blank limit]
512 M.
[Data scale and Conventions]
A total of 10 test points, with the data Scope meeting:
N, k <= 500000
All data meets the requirements:-1000 ≤ AI ≤, 1 ≤ L ≤ r ≤ n, and there must be music that meets the requirements.
Question:
After thinking about it, it feels like the sum of the two Arrays on wikioi, and finding the N and
But another thought, K times would be required, K = 500000. The answer is certainly not ...... Then I found that I wouldn't be able to. When I look at the problem, it's still true ......
Alas, tears are everywhere ......
Sometimes such an idea is abandoned, with 100 points in the test room.
Code: