#Q192. 「一本通 5.6 练习 3」特别行动队
「一本通 5.6 练习 3」特别行动队
Description
Original Source: APIO 2010
You have a troop of reserve soldiers, each numbered from to , and you need to split them into several special action teams to deploy into the battlefield. For the sake of synergy, the soldiers in the same special action team should have consecutive numbers, forming a sequence like . The initial combat power of soldier is , and the initial combat power of a special action team is the sum of the initial combat powers of its members, i.e., . Through long-term observation, you have derived an empirical formula that adjusts the initial combat power of a special action team to as follows: , where are known coefficients (). As the commander, your task is to organize the troop into teams such that the sum of the adjusted combat powers of all special action teams is maximized. Determine this maximum sum. For example, suppose you have 4 soldiers with , , , and . The coefficients in the empirical formula are , , and . The optimal strategy is to form 3 special action teams: the first team includes soldiers and , the second team includes soldier , and the third team includes soldier . The initial combat powers of the teams are , , and , respectively, and their adjusted combat powers are , , and . The total adjusted combat power is , and no other grouping yields a larger sum.
Input Format
The input consists of three lines. The first line contains an integer , the total number of soldiers. The second line contains three integers , the coefficients in the empirical formula. The third line contains space-separated integers , representing the initial combat powers of soldiers numbered .
Output Format
Output an integer representing the maximum possible sum of the adjusted combat powers of all special action teams.
Sample 1
4
-1 10 -20
2 2 3 4
9
Constraints and Hints
of the data satisfies ; of the data satisfies ; of the data satisfies , , , and .