#P5858. 「SWTR-3」Golden Sword
「SWTR-3」Golden Sword
Background
Little E unfortunately lost his golden sword in a battle.
Problem Description
To make a golden sword, kinds of materials are needed, numbered from to . The sturdiness value of material is .
Alchemy pays great attention to the order of adding materials, so Little E must add these materials into the alchemy pot in the order from to , one by one.
However, the pot has a very limited capacity: it can hold at most materials.
Fortunately, before adding each material, Little E may take out some materials from the pot, but the number taken out cannot exceed .
- We define the durability of material as: (the total number of materials in the pot when adding material , including the material being added) . Then, the sword's durability is the sum of the durabilities of all materials.
Little E of course wants his sword's durability to be as large as possible, so that he can take it into more battles. Please output the maximum possible durability.
Note: Here, “the total number of materials in the pot when adding material ” includes the material currently being put into the pot. For details, see the samples.
Input Format
The first line contains three integers .
The second line contains integers .
Output Format
Output one integer in one line, representing the maximum durability.
5 3 3
1 3 2 4 5
40
5 3 3
1 -3 -2 4 5
21
7 4 2
-5 3 -1 -4 7 -6 5
17
5 3 1
-1 -3 -2 -4 -5
-15
Hint
"Sample Explanation"
- For Sample 1, one feasible optimal plan is:
First put in material 1. Now there is material in the pot, and the durability is .
Then put in material 2. Now there are materials in the pot, and the durability is .
Then put in material 3. Now there are materials in the pot, and the durability is .
Take out material 1, then put in material 4. Now there are materials in the pot, and the durability is .
Take out material 4, then put in material 5. Now there are materials in the pot, and the durability is .
The final answer is . - For Sample 2, one feasible optimal plan is:
Put in material 1, and the durability is .
Take out material 1, put in material 2, and the durability is .
Put in material 3, and the durability is .
Put in material 4, and the durability is .
Take out material 2, put in material 5, and the durability is .
The final answer is . - For Sample 3, one feasible optimal plan is:
. - For Sample 4, one feasible optimal plan is:
.
"Constraints and Notes"
This problem uses bundled testdata.
- Subtask #1 (15 points): .
- Subtask #2 (5 points): , .
- Subtask #3 (15 points): .
- Subtask #4 (15 points): .
- Subtask #5 (5 points): .
- Subtask #6 (10 points): .
- Subtask #7 (10 points): .
- Subtask #8 (25 points): no special restrictions.
For of the data, , . For Subtask , .
"Help / Notes"
This problem provides large samples. For the exact input and output, see gold01-08.in / gold01-08.out in Big Sample. Extraction code: 757d.
The filenames correspond one-to-one with the Subtask numbers.
"Source"
Sweet Round 03 D.
Idea & solution: ET2006.
Translated by ChatGPT 5