DMPG '18 G2 - Gardening Fun

View as PDF

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
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

Bob is working on his biology assignment! He has plants in a row and needs to water all of them today. Bob wants to water the plant with milliliters of water. He can spray exactly milliliter of water onto each plant in a contiguous row of length at a cost of where and are given positive integers.

Bob is also okay with cutting some corners with his plant project. Specifically, say he ends up watering the plant with milliliters. Then he will consider as an additional cost, where is some given positive integer.

Help Bob minimize the sum of these costs!

for all

Input Specification

The first line contains a single integer .
The next line contains three space-separated integers in that order.
The final line contains space-separated integers .

Output Specification

Output a single integer, the minimum possible sum of the costs.

Sample Input 1

5
1 9 8
1 1 0 1 1

Sample Output 1

22

Sample Input 2

8
1 2 100
2 2 0 1 0 1 1 1

Sample Output 2

16