APIO '10 P1 - Commando

View as PDF

Points: 20 (partial)
Time limit: 0.6s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

You are the commander of a troop of soldiers, numbered from to . For the battle ahead, you plan to divide these soldiers into several commando units. To promote unity and boost morale, each unit will consist of a contiguous sequence of soldiers of the form .

Each soldier has a battle effectiveness rating . Originally, the battle effectiveness of a commando unit was computed by adding up the individual battle effectiveness of the soldiers in the unit. In other words, .

However, years of glorious victories have led you to conclude that the battle effectiveness of a unit should be adjusted as follows: the adjusted effectiveness is computed by using the equation , where , , are known coefficients , is the original effectiveness of the unit.

Your task as commander is to divide your soldiers into commando units in order to maximize the sum of the adjusted effectiveness of all the units.

For instance, suppose you have soldiers, , , , . Further, let the coefficients for the equation to adjust the battle effectiveness of a unit be , , . In this case, the best solution is to divide the soldiers into three commando units: The first unit contains soldiers and , the second unit contains soldier , and the third unit contains soldier . The battle effectiveness of the three units are , , respectively, and the adjusted effectiveness are , , respectively. The total adjusted effectiveness for this grouping is and it can be checked that no better solution is possible.

Input Specification

The input consists of three lines. The first line contains a positive integer , the total number of soldiers. The second line contains integers , , and , the coefficients for the equation to adjust the battle effectiveness of a commando unit. The last line contains integers , separated by spaces, representing the battle effectiveness of soldiers , respectively.

Output Specification

A single line with an integer indicating the maximum adjusted effectiveness achievable.

Sample Input

4
-1 10 -20
2 2 3 4

Sample Output

9

Constraints

• In of the test cases, ;
• In of the test cases, ;
• In of the test cases, , , , and .