CF241A.Old Peykan

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There are nn cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1,c2,...,cnc_{1},c_{2},...,c_{n} . The Old Peykan wants to travel from city c1c_{1} to cnc_{n} using roads. There are (n1)(n-1) one way roads, the ii -th road goes from city cic_{i} to city ci+1c_{i+1} and is did_{i} kilometers long.

The Old Peykan travels 1 kilometer in 1 hour and consumes 1 liter of fuel during this time.

Each city cic_{i} (except for the last city cnc_{n} ) has a supply of sis_{i} liters of fuel which immediately transfers to the Old Peykan if it passes the city or stays in it. This supply refreshes instantly kk hours after it transfers. The Old Peykan can stay in a city for a while and fill its fuel tank many times.

Initially (at time zero) the Old Peykan is at city c1c_{1} and s1s_{1} liters of fuel is transferred to it's empty tank from c1c_{1} 's supply. The Old Peykan's fuel tank capacity is unlimited. Old Peykan can not continue its travel if its tank is emptied strictly between two cities.

Find the minimum time the Old Peykan needs to reach city cnc_{n} .

输入格式

The first line of the input contains two space-separated integers mm and kk (1<=m,k<=1000)(1<=m,k<=1000) . The value mm specifies the number of roads between cities which is equal to n1n-1 .

The next line contains mm space-separated integers d1,d2,...,dmd_{1},d_{2},...,d_{m} (1<=di<=1000)(1<=d_{i}<=1000) and the following line contains mm space-separated integers s1,s2,...,sms_{1},s_{2},...,s_{m} (1<=si<=1000)(1<=s_{i}<=1000) .

输出格式

In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cnc_{n} from city c1c_{1} .

输入输出样例

  • 输入#1

    4 6
    1 2 5 2
    2 3 3 4
    

    输出#1

    10
    
  • 输入#2

    2 3
    5 6
    5 5
    

    输出#2

    14
    

说明/提示

In the second sample above, the Old Peykan stays in c1c_{1} for 3 hours.

首页