CF319C.Kalila and Dimna in the Logging Industry

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

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 nn trees with heights a1,a2,...,ana_{1},a_{2},...,a_{n} . They bought a chain saw from a shop. Each time they use the chain saw on the tree number ii , 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 ii (the tree that have height aia_{i} in the beginning), then the cost of charging the chain saw would be bib_{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 ii < jj , a_{i}<a_{j} and b_{i}>b_{j} and also bn=0b_{n}=0 and a1=1a_{1}=1 . Kalila and Dimna want to cut all the trees completely, with minimum cost.

They want you to help them! Will you?

输入格式

The first line of input contains an integer nn ( 1<=n<=1051<=n<=10^{5} ). The second line of input contains nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=1091<=a_{i}<=10^{9} ). The third line of input contains nn integers b1,b2,...,bnb_{1},b_{2},...,b_{n} ( 0<=bi<=1090<=b_{i}<=10^{9} ).

It's guaranteed that a1=1a_{1}=1 , bn=0b_{n}=0 , a_{1}<a_{2}<...<a_{n} and b_{1}>b_{2}>...>b_{n} .

输出格式

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.

输入输出样例

  • 输入#1

    5
    1 2 3 4 5
    5 4 3 2 0
    

    输出#1

    25
    
  • 输入#2

    6
    1 2 3 10 20 30
    6 5 4 3 2 0
    

    输出#2

    138
    
首页