National Olympiad in Informatics, China, 2010
Little Z is a minorly famous pianist. Recently, Doctor C has gifted him with a super piano. With it, little Z hopes to create the world's most enchanting music.
The super piano has different keys in a row, numbered from
to
. The value of the
-th key is
, where
can be positive or negative.
A chord consists of a sequence of between and
consecutive keys. Two chords are considered the same if they contain the same sequence of notes.
We define the value of a chord as the sum of the values of all its notes.
Little Z decides to compose a piece consisting of different chords. Note that the chords are independent, so may overlap. Find the maximum sum of values of these chords.
Input Specification
The first line contains four positive integers ,
,
, and
.
represents the number of keys on the super piano.
represents
the number of different chords that the piece should consist of.
and
respectively represent the minimum and maximum number of keys that can
be in a single chord.
The next lines each contain one integer, with the
-th line containing
.
Output Specification
The output consists of a single integer, the maximum possible value of a piece that little Z can compose.
Sample Input
4 3 2 3
3
2
-6
8
Sample Output
11
Explanation
There are possible super chords:
- Notes
to
, for a total value of
- Notes
to
, for a total value of
- Notes
to
, for a total value of
- Notes
to
, for a total value of
- Notes
to
, for a total value of
The maximum value chords are ,
, and
, for a total of
.
Constraints
There are total test cases with bounds satisfying:
Test Case | ||
---|---|---|
All of the test cases satisfy and
.
Furthermore, it is guaranteed that a composition fitting the requirements will exist.
Problem translated to English by , editted by .
Comments