Commando
Time limit1sMemory limit64 MB
Partition soldiers into consecutive blocks, each block's score is a concave quadratic of its sum, and maximize the total score.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Divide and conquer, Prefix sum, Math
- Solved
- No attempts yet
Problem
A commander leads an army of soldiers numbered from to . For the coming battles the commander wants to split the soldiers into several commando units. To build cohesion and morale, each unit must consist of soldiers with consecutive numbers, that is, of the form .
Each soldier has combat power . The raw combat power of a unit was originally the sum of its soldiers' powers, .
After many glorious victories, however, the army decided to adjust a unit's combat power as follows: the adjusted combat power of a unit is where , , are known coefficients with , and is the unit's raw combat power defined above.
Your task is to split the soldiers into commando units so that the sum of the adjusted combat powers of all units is as large as possible.
Input
The input consists of three lines. The first line contains a positive integer , the number of soldiers. The second line contains three integers , , , the coefficients of the adjusted-power formula. The third line contains integers , separated by spaces, the combat powers of soldiers .
, , , , .
Output
Print a single integer: the maximum total adjusted combat power that can be achieved.