-
Notifications
You must be signed in to change notification settings - Fork 0
/
182B.cpp
73 lines (66 loc) · 1.29 KB
/
182B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <algorithm>
#include <vector>
#define MOD 1000000007
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#define ll long long
#include <cmath>
#include <cstdlib>
#define inf 1000007
#include <ctime>
#define exit return 0
using namespace std;
int N, a, b, d, dist, c, m;
int K;
ll dp[inf];
int in[inf];
int benefit[1234];
int X[1234], Y[1234];
int gr[1234][1234];
int floyd[1234][1234];
int main(){
/*cin >> N >> d;*/
scanf("%d %d", &N, &d);
for (int i = 2; i <= N - 1; i++){
//cin >> benefit[i];
scanf("%d", &benefit[i]);
}
for (int i = 1; i <= N; i++){
//cin >> X[i] >> Y[i];
scanf("%d %d", &X[i], &Y[i]);
}
for (int i = 1; i <= N; i++){
for (int j = 1; j <= N; j++){
if (i == j){
floyd[i][j] = floyd[j][i] = 0;
}
else{
floyd[i][j] = (abs(X[i] - X[j]) + abs(Y[i] - Y[j]))*d - benefit[j];
}
}
}
for (int k = 1; k <= N; k++){
for (int i = 1; i <= N; i++){
for (int j = 1; j <= N; j++){
floyd[i][j] = min(floyd[i][j], floyd[i][k] + floyd[k][j]);
}
}
}
//cout << floyd[1][N];
printf("%d", floyd[1][N]);
exit;
}