Every Halloween, amount of candy from each house . This year, he wants to maximize the amount of he candy can obtain before running out of energy. At first, he is dropped off at a single house can walk to adjacent houses and which are both exactly one distance away from each other. For every house passes by (including the one he is dropped off at), he can claim amount of candy from the house exactly once (he cannot visit the same house twice). Throughout the night, can walk a total of distance from the starting house before running out of energy. What is the maximum amount of candy can obtain before running out of energy?
loves to go trick or treating, an activity that consists of trick or treaters visiting different houses and obtainingInput Specification
The first line of input will contain two integers, the number of houses in a row and the amount of energy has.
The next line will contain integers, representing the amount of candy each house will give out.
Python users are recommended to submit in PyPy3
Output Specification
Output the maximum amount of candy
can obtain before he runs out of energy.Subtasks
Batch 1 [10%]
Batch 2 [20%]
Batch 3 [20%]
Batch 4 [50%]
Sample Input 1
10 2
1 2 3 4 5 6 7 8 9 10
Sample Output 1
27
Explanation for Sample Output 1
The maximum amount of candy
This can be obtained by being dropped off at house 8, walking to house 9, and then to house 10 for a total distance of 2.
During this walk, he can collect 27 candy from the houses he passes by: 8 candies from house 8, 9 candies from house 9, and 10 candies from house 10.
Sample Input 2
10 4
8 0 2 14 8 3 5 0 9 5
Sample Output 2
32
Explanation for Sample Output 2
There are two ways to obtain this maximum value of 32.
If is dropped of at house 5 and walk 4 units to the left, or he can be dropped of at house 3 and walk 4 houses to the right.
8 + 14 + 2 + 0 + 8 = 32
or 2 + 14 + 8 + 3 + 5
.
Comments