CF301B.Yaroslav and Time

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has nn clock stations, station number ii is at point (xi,yi)(x_{i},y_{i}) of the plane. As the player visits station number ii , he increases the current time on his timer by aia_{i} . The stations are for one-time use only, so if the player visits some station another time, the time on his timer won't grow.

A player spends ddistd·dist time units to move between stations, where distdist is the distance the player has covered and dd is some constant. The distance between stations ii and jj is determined as xixj+yiyj|x_{i}-x_{j}|+|y_{i}-y_{j}| .

Initially, the player is at station number 11 , and the player has strictly more than zero and strictly less than one units of time. At station number 11 one unit of money can increase the time on the timer by one time unit (you can buy only integer number of time units).

Now Yaroslav is wondering, how much money he needs to get to station nn . Help Yaroslav. Consider the time to buy and to increase the timer value negligibly small.

输入格式

The first line contains integers nn and dd (3<=n<=100,103<=d<=105)(3<=n<=100,10^{3}<=d<=10^{5}) — the number of stations and the constant from the statement.

The second line contains n2n-2 integers: a2,a3,...,an1a_{2},a_{3},...,a_{n-1} (1<=ai<=103)(1<=a_{i}<=10^{3}) . The next nn lines contain the coordinates of the stations. The ii -th of them contains two integers xix_{i} , yiy_{i} (( - 100<=xi,yi<=100)100<=x_{i},y_{i}<=100) .

It is guaranteed that no two stations are located at the same point.

输出格式

In a single line print an integer — the answer to the problem.

输入输出样例

  • 输入#1

    3 1000
    1000
    0 0
    0 1
    0 3
    

    输出#1

    2000
    
  • 输入#2

    3 1000
    1000
    1 0
    1 1
    1 2
    

    输出#2

    1000
    
首页