#P4217. [CTSC2010] 产品销售

[CTSC2010] 产品销售

Description

Company A is seeing strong sales of a certain computer product. As the CEO of Company A, Xiao A plans to make a detailed production and sales plan for the next consecutive NN sales quarters. It is known that in the ii-th sales quarter the order quantity is DiD_i. In quarter ii, Company A may meet the orders in the following ways:

  • Produce new products in quarter ii to sell.
  • If there is remaining inventory before quarter ii, it can be sold directly in quarter ii (note that there is no inventory before the first quarter).
  • In quarter ii, it is allowed to leave part of the orders unfilled and postpone them, merging them into the order quantity of the next quarter (i+1)(i + 1).

Company A needs to consider the following costs: the production cost for new products, the additional storage cost for inventory, and the compensation paid to users for delayed orders. Moreover, due to labor and resource limitations, the number of new products that can be produced in each sales quarter is limited, and both the costs and production upper bounds differ by quarter, as follows:

  • In quarter ii, at most UiU_i new units can be produced, and the cost per unit is PiP_i.
  • Products kept at the end of quarter ii for use in later quarters incur a storage fee: for each unit kept from quarter ii to quarter i+1i + 1, an extra fee of MiM_i must be paid (note that once kept to the next quarter, the product may remain in inventory again).
  • For each unit postponed from quarter ii and merged into the next quarter’s order quantity, Company A must compensate users CiC_i (note that an order postponed to the next quarter may be postponed again, and the fee is charged according to the later quarter’s delay fee).

By the end of quarter NN, Company A must have fulfilled all user orders. It is guaranteed that the total number of units the company can produce is not less than the total order quantity; that is, there exists at least one production and sales plan that satisfies all orders. Xiao A wants to know how to arrange production and sales so that, while satisfying all orders, the total cost is minimized.

Input Format

The first line of the input file product.in\tt{product.in} contains a positive integer NN, the number of sales quarters.

The second line contains NN non-negative integers D1,D2,,DND_1, D_2, \ldots, D_N, where DiD_i is the order quantity in quarter ii.

The third line contains NN non-negative integers U1,U2,,UNU_1, U_2, \ldots, U_N, where UiU_i is the maximum number of new units that can be produced in quarter ii.

The fourth line contains NN non-negative integers P1,P2,,PNP_1, P_2, \ldots, P_N, where PiP_i is the per-unit production cost in quarter ii.

The fifth line contains N1N - 1 non-negative integers M1,M2,,MN1M_1, M_2, \ldots, M_{N-1}, where MiM_i is the additional storage fee to keep one unit from quarter ii to quarter i+1i + 1.

The sixth line contains N1N - 1 non-negative integers C1,C2,,CN1C_1, C_2, \ldots, C_{N-1}, where CiC_i is the compensation paid if one unit’s order is not fulfilled in quarter ii and is merged into the order quantity of quarter i+1i + 1.

Output Format

The output file product.out\tt{product.out} contains a single non-negative integer, the minimal total cost.

4
3 2 1 2
2 5 2 2
5 1 5 5
1 2 1
5 3 3
30

Hint

Sample Explanation:

In the first quarter, produce 22 units. In the second quarter, produce 55 units. In the third quarter, produce no units. In the fourth quarter, produce 11 unit. The production cost is 25+51+05+15=202 * 5 + 5 * 1 + 0 * 5 + 1 * 5 = 20.

Since at most 22 units can be produced in the first quarter, the 33-unit order cannot be fully met; thus 11 unit is postponed to the second quarter, incurring a compensation of 55.

In the second quarter, because 11 unit was postponed from the first quarter, the order quantity becomes 33. This quarter produces 55 units, leaving 22 units in inventory. In the third quarter, sell directly from inventory; the extra 11 unit is further stored to the fourth quarter. Together with producing 11 unit in the fourth quarter, all orders are satisfied. The total storage cost is 22+11=52 * 2 + 1 * 1 = 5.

The total cost is 20+5+5=3020 + 5 + 5 = 30.

Constraints:

  • For 30%30\% of the testdata, N1,000N \leq 1{,}000.
  • For 100%100\% of the testdata, 1N100,0001 \leq N \leq 100{,}000, 1Di,Ui,Pi,Mi,Ci10,0001 \leq D_i, U_i, P_i, M_i, C_i \leq 10{,}000.

Translated by ChatGPT 5