354A.md (2373B)
1 Source: https://codeforces.com/problemset/problem/354/A 2 3 A. Vasya and Robot 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 Vasya has *n* items lying in a line. The items are consecutively numbered by numbers from 1 to *n* in such a way that the leftmost item has number 1, the rightmost item has number *n*. Each item has a weight, the *i*-th item weights *w**i* kilograms. 22 23 Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions: 24 25 1. Take the leftmost item with the left hand and spend *w**i* · *l* energy units (*w**i* is a weight of the leftmost item, *l* is some parameter). If the previous action was the same (left-hand), then the robot spends extra *Q**l* energy units; 26 2. Take the rightmost item with the right hand and spend *w**j* · *r* energy units (*w**j* is a weight of the rightmost item, *r* is some parameter). If the previous action was the same (right-hand), then the robot spends extra *Q**r* energy units; 27 28 Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items. 29 30 Input 31 32 The first line contains five integers *n*, *l*, *r*, *Q**l*, *Q**r* (1 ≤ *n* ≤ 105; 1 ≤ *l*, *r* ≤ 100; 1 ≤ *Q**l*, *Q**r* ≤ 104). 33 34 The second line contains *n* integers *w*1, *w*2, ..., *w**n* (1 ≤ *w**i* ≤ 100). 35 36 Output 37 38 In the single line print a single number — the answer to the problem. 39 40 Examples 41 42 Input 43 44 ``` 45 3 4 4 19 1 46 42 3 99 47 ``` 48 49 Output 50 51 ``` 52 576 53 ``` 54 55 Input 56 57 ``` 58 4 7 2 3 9 59 1 2 3 4 60 ``` 61 62 Output 63 64 ``` 65 34 66 ``` 67 68 Note 69 70 Consider the first sample. As *l* = *r*, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units. 71 72 The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.