题库练习 N Machines
← 上一题 下一题 →

A15532 | N Machines

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You have been invited as a production process optimization specialist to some very large company. The company has $n$ machines at its factory, standing one behind another in the production chain. Each machine can be described in one of the following two ways: $(+,~a_i)$ or $(*,~a_i)$ .

If a workpiece with the value $x$ is supplied to the machine of kind $(+,~a_i)$ , then the output workpiece has value $x + a_i$ .

If a workpiece with the value $x$ is supplied to the machine of kind $(*,~a_i)$ , then the output workpiece has value $x \cdot a_i$ .

The whole production process is as follows. The workpiece with the value $1$ is supplied to the first machine, then the workpiece obtained after the operation of the first machine is supplied to the second machine, then the workpiece obtained after the operation of the second machine is supplied to the third machine, and so on. The company is not doing very well, so now the value of the resulting product does not exceed $2 \cdot 10^9$ .

The directors of the company are not satisfied with the efficiency of the production process and have given you a budget of $b$ coins to optimize it.

To optimize production you can change the order of machines in the chain. Namely, by spending $p$ coins, you can take any machine of kind $(+,~a_i)$ and move it to any place in the chain without changing the order of other machines. Also, by spending $m$ coins, you can take any machine of kind $(*,~a_i)$ and move it to any place in the chain.

What is the maximum value of the resulting product that can be achieved if the total cost of movements that are made should not exceed $b$ coins?

输入格式

The first line contains four integers $n$ , $b$ , $p$ and $m$ ( $1 \le n \le 10^6$ , $1 \le b, p, m \le 10^9$ ) — the number of machine at the factory, your budget and costs of movements of both kinds of machines.

Each of the following $n$ lines contains description of a machine. The description begins with one of the following characters: "+" or "\*", that denotes the kind of the machine. Then an integer $a_i$ follows ( $1 \le a_i \le 2 \cdot 10^9$ ).

It's guaranteed that the current value of the resulting product does not exceed $2 \cdot 10^9$ .

输出格式

Print one integer — the maximum value of the resulting product that can be achieved if the total cost of movements that are made does not exceed $b$ coins.

输入输出样例

输入 #1
3 2 1 3
* 2
+ 1
+ 1
输出 #1
6
输入 #2
4 2 2 2
* 2
+ 1
* 3
+ 2
输出 #2
21
输入 #3
8 2 1 1
* 2
+ 1
* 4
+ 1
+ 1
+ 1
* 5
+ 3
输出 #3
240
C++ 编辑器
输入
输出