P18131 [ICPC 2026 Seoul R] Workbench
Description
A workshop has a storeroom and a workbench. It turns a raw part into a finished product through $n$ processing steps, numbered from $1$ to $n$, which are carried out in this order. There are $n+1$ parts, numbered from $0$ to $n$: step $i$ takes part $i-1$ and produces part $i$, so part $0$ is the raw material and part $n$ is the finished product. Step $i$ involves $f_i$ units of work, and part $i$ has size $s_i$.
The steps are carried out in batches. That is, the steps $1,\ldots,n$ are partitioned into intervals, and the batches are carried out one after another in the order of the intervals. A batch $[l,r]$ consists of steps $l$ through $r$, inclusive. Its input part $l-1$ is brought from the storeroom to the workbench, and its output part $r$ is put back into the storeroom. Its intermediate parts $l,\ldots,r-1$ never leave the workbench.
Let $m$ be the area of the workbench. While a batch $[l,r]$ is carried out, all of its intermediate parts must be on the workbench at the same time, so the batch is valid only if $s_l+\cdots+s_{r-1} \le m$. The input and output parts do not count toward this area. A batch of a single step has no intermediate parts, so it is always valid.
The workshop has a processing rate $a$, the amount of work done per unit time, and a transport rate $b$, the total size of parts carried between the storeroom and the workbench per unit time. For simplicity, we assume that processing and transport within a batch fully overlap. Thus, the time taken by a batch $[l,r]$ is the larger of the processing time $(f_l+\cdots+f_r)/a$ and the transport time $(s_{l-1}+s_r)/b$. Multiplying this time by $a\times b$ gives an integer, which we call the cost of the batch:
$$
\operatorname{cost}(l,r)=\max\bigl((f_l+\cdots+f_r)\times b,\ (s_{l-1}+s_r)\times a\bigr).
$$
For example, suppose that $a=5$ and $b=8$, and consider a batch of two steps involving $11$ and $10$ units of work. If its input and output parts have sizes $8$ and $11$, respectively, the cost of the batch is $\max(21\times 8,19\times 5)=168$.
The total cost of a partition is the sum of the costs of its batches. Since carrying out every step as a separate batch is always valid, at least one partition of the steps into valid batches exists. Write a program to find the minimum total cost over all partitions of the steps into valid batches.
Input Format
Your program is to read from standard input. The input starts with a line containing an integer $n$ ($1 \le n \le 2 \times 10^5$), where $n$ is the number of steps.
The second line contains three integers $a$, $b$, and $m$ ($1 \le a,b \le 10^6$, $0 \le m \le 10^{12}$), where $a$ is the processing rate, $b$ is the transport rate, and $m$ is the area of the workbench.
The third line contains $n$ integers $f_1,f_2,\ldots,f_n$ ($1 \le f_i \le 10^6$ for $1 \le i \le n$), where $f_i$ is the amount of work involved in step $i$.
The fourth line contains $n+1$ integers $s_0,s_1,\ldots,s_n$ ($1 \le s_i \le 10^6$ for $0 \le i \le n$), where $s_i$ is the size of part $i$.
Output Format
Your program is to write to standard output. Print exactly one line. The line should contain the minimum total cost over all partitions of the steps into valid batches.