CF354A.Vasya and Robot

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

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:

  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;
  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;

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.

瓦西里有 nn 个物品排成一行。这些物品从左到右依次编号为 11 到 nn,其中最左边的物品编号为 11,最右边的物品编号为 nn。每个物品都有一个重量,第 ii 个物品的重量为 wiw_i 千克。

瓦西里需要收集所有这些物品,但他不会亲自完成这项任务。他使用自己崭新的机器人。该机器人拥有两只不同的机械臂——左手和右手。机器人可以依次执行以下操作:

  1. 用左手取走最左边的物品,并消耗 wi⋅lw_i \cdot l 个能量单位(其中 wiw_i 是最左边物品的重量,ll 是某个参数)。如果上一次操作也是左手操作,则机器人额外消耗 QlQ_l 个能量单位;
  2. 用右手取走最右边的物品,并消耗 wj⋅rw_j \cdot r 个能量单位(其中 wjw_j 是最右边物品的重量,rr 是某个参数)。如果上一次操作也是右手操作,则机器人额外消耗 QrQ_r 个能量单位。

显然,瓦西里希望以尽可能节省能量的方式对机器人进行编程。他请你解决这个问题。你的任务是求出机器人收集所有物品所需的最小能量单位数。

输入格式

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).

The second line contains n integers _w_1, _w_2, ..., w__n (1 ≤ w__i ≤ 100).

第一行包含五个整数 nn、ll、rr、QlQ_l、QrQ_r(1 ≤ n ≤ 1051 \le n \le 10^5;1 ≤ l, r ≤ 1001 \le l,\,r \le 100;1 ≤ Ql, Qr ≤ 1041 \le Q_l,\,Q_r \le 10^4)。

第二行包含 nn 个整数 w1, w2, ..., wnw_1,\,w_2,\,...,\,w_n(1 ≤ wi ≤ 1001 \le w_i \le 100)。

输出格式

In the single line print a single number — the answer to the problem.

在单行中输出一个数字——即该问题的答案。

输入输出样例

  • 输入#1

    3 4 4 19 1
    42 3 99

    输出#1

    576
  • 输入#2

    4 7 2 3 9
    1 2 3 4

    输出#2

    34

说明/提示

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.

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.

考虑第一个样例。由于 l=rl = r,我们可以轮流从左右两侧取物品:首先从左侧取一个,然后从右侧取一个,最后再从左侧取一个。机器人总共消耗的能量为 4⋅42+4⋅99+4⋅3=5764 \cdot 42 + 4 \cdot 99 + 4 \cdot 3 = 576 单位。

第二个样例。最优策略是:先从右侧取一个物品,再从左侧取一个物品,最后连续从右侧取两个物品。机器人总共消耗的能量为 (2⋅4)+(7⋅1)+(2⋅3)+(2⋅2+9)=34(2 \cdot 4) + (7 \cdot 1) + (2 \cdot 3) + (2 \cdot 2 + 9) = 34 单位。

输入解题思路,AI测评打分。不知道怎么写?

首页