CF1753E.N Machines

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

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

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

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

The whole production process is as follows. The workpiece with the value 11 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 21092 \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 bb coins to optimize it.

To optimize production you can change the order of machines in the chain. Namely, by spending pp coins, you can take any machine of kind (+, ai)(+,~a_i) and move it to any place in the chain without changing the order of other machines. Also, by spending mm coins, you can take any machine of kind (, ai)(*,~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 bb coins?

输入格式

The first line contains four integers nn , bb , pp and mm ( 1n1061 \le n \le 10^6 , 1b,p,m1091 \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 nn 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 aia_i follows ( 1ai21091 \le a_i \le 2 \cdot 10^9 ).

It's guaranteed that the current value of the resulting product does not exceed 21092 \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 bb 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

说明/提示

In the first example our budget is too low to move machine (, 2)(*,~2) , but we can move both machines (+, 1)(+,~1) to the beginning of the chain. So the final chain will be (+, 1)(+,~1) (+, 1)(+,~1) (, 2)(*,~2) . If the workpiece with the value 11 is supplied to the first machine, its value will be changed in the following way: 1,2,3,61, 2, 3, 6 .

In the second example we can move only one machine. Let's move machine (+, 2)(+,~2) to the beginning of the chain. The final chain will be (+, 2)(+,~2) (, 2)(*,~2) (+, 1)(+,~1) (, 3)(*,~3) . The value of the workpiece will be changed in the following way: 1,3,6,7,211, 3, 6, 7, 21 .

In the third example we can place machine (, 4)(*,~4) before the machine (, 5)(*,~5) , and move machine (+, 3)(+,~3) to the beginning of the chain. The final chain will be (+, 3)(+,~3) (, 2)(*,~2) (+, 1)(+,~1) (+, 1)(+,~1) (+, 1)(+,~1) (+, 1)(+,~1) (, 4)(*,~4) (, 5)(*,~5) . The value of the workpiece will be changed in the following way: 1,4,8,9,10,11,12,48,2401, 4, 8, 9, 10, 11, 12, 48, 240 .

首页