Soil - MarisaOJ: Marisa Online Judge

Soil

Time limit: 1000 ms
Memory limit: 256 MB
Marisa has a garden with $n$ plots, and each plot $i$ initially contains $A_i$ units of soil. Marisa wants to modify the amount of soil in each plot so that they contain $B_i$ units of soil. Marisa can perform the following actions, each with its associated cost: - Buy an additional unit of soil at a cost of $x$. - Dump a unit of soil from a plot at a cost of $y$. - Move an unit of soil from plot $i$ to plot $j$ at a cost of $|i-j| \times z$. Your task is to determine the minimum cost for Marisa to renovate her garden by adjusting the soil in each plot. ### Input - The first line contains four integers $n,x,y,z$. - The next $n$ lines, each line contains two integers $A_i,B_i$. ### Output - Print an integer, the minimum cost. ### Constraints - $1 \le n \le 500$. - $1 \le x, y, z \le 1000$. - $0 \le A_i, B_i \le 10$. ### Example Input: ``` 4 100 200 1 1 4 2 3 3 2 4 0 ``` Output: ``` 210 ```