Paul loves the song Never Gonna Give You Up and often plays it on his laptop at maximum volume for his friends to enjoy too.
However, Paul thinks that the maximum volume on his laptop is not loud enough. So, he has bought a huge boombox with speakers on it to play the song. The speakers are arranged evenly in a row, where the distance between every pair of adjacent speakers is metre. To better identify these speakers, Paul has numbered them in order and has given each one an integer value representing its relative loudness.
Even with the boombox, Paul finds that the sound is not loud enough. So, he has borrowed batteries from his friend to amplify the speakers. Each battery can amplify a single speaker and will increase its loudness by a factor of . Each speaker may be amplified at most once.
Paul would like to amplify speakers in a way that maximizes the final sum of the loudness values. However, to protect his ears, Paul will not amplify two speakers if they are strictly less than metres away.
Please help Paul find the maximum possible sum if he can amplify up to speakers.
Input Specification
The first line of input will contain four space-separated integers, , , , and .
The next line will contain space-separated integers, .
Subtask 1 [20%]
Subtask 2 [30%]
Subtask 3 [50%]
No additional constraints.
Output Specification
Output a single integer, the maximum sum of the loudness values after amplifying up to speakers.
It is guaranteed that the answer will fit in a 32-bit integer.
Sample Input 1
5 3 3 2
1 4 8 3 5
Sample Output 1
30
Explanation for Sample Output 1
Paul can amplify speakers and (which are metres apart) to get the sum .
Sample Input 2
8 4 2 3
1 8 2 8 6 7 9 1
Sample Output 2
92
Explanation for Sample Output 2
Paul can amplify speakers , , and to get a sum of .
Comments