Codeforces Round 189 (Div. 1)
C
Kalila and Dimna in the Logging Industry
Codeforces
2100
原题
← BD →
翻译中…

Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.

翻译中…

The manager of logging factory wants them to go to the jungle and cut $*n*$ trees with heights $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$. They bought a chain saw from a shop. Each time they use the chain saw on the tree number $*i*$, they can decrease the height of this tree by one unit. Each time that Kalila and Dimna use the chain saw, they need to recharge it. Cost of charging depends on the id of the trees which have been cut completely (a tree is cut completely if its height equal to 0). If the maximum id of a tree which has been cut completely is $*i*$ (the tree that have height $*a*_{*i*}$ in the beginning), then the cost of charging the chain saw would be $*b*_{*i*}$. If no tree is cut completely, Kalila and Dimna cannot charge the chain saw. The chainsaw is charged in the beginning. We know that for each $*i*$ < $*j*$, $*a*_{*i*} < *a*_{*j*}$ and $*b*_{*i*} > *b*_{*j*}$ and also $*b*_{*n*} = 0$ and $*a*_{1} = 1$. Kalila and Dimna want to cut all the trees completely, with minimum cost.

翻译中…

They want you to help them! Will you?

翻译中…

Input

翻译中…

The first line of input contains an integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$). The second line of input contains $*n*$ integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($1 ≤ *a*_{*i*} ≤ 10^{9}$). The third line of input contains $*n*$ integers $*b*_{1}, *b*_{2}, ..., *b*_{*n*}$ ($0 ≤ *b*_{*i*} ≤ 10^{9}$).

翻译中…

It's guaranteed that $*a*_{1} = 1$, $*b*_{*n*} = 0$, $*a*_{1} < *a*_{2} < ... < *a*_{*n*}$ and $*b*_{1} > *b*_{2} > ... > *b*_{*n*}$.

翻译中…

Output

翻译中…

The only line of output must contain the minimum cost of cutting all the trees completely.

翻译中…

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

翻译中…

样例

Input #1
5
1 2 3 4 5
5 4 3 2 0
Output #1
25
InputCopy OutputCopy
Input #2
6
1 2 3 10 20 30
6 5 4 3 2 0
Output #2
138
InputCopy OutputCopy
题目信息
题号
319C
时间限制
2 s
内存限制
256 MB
标签
动态规划
计算几何

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。