A - センサーデータの修復

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 266

問題文

高橋君は N 個のセンサーが一列に並んだ観測システムを管理しています。各センサーには 1 から N までの番号が付けられており、正常時における i 番目のセンサーの計測値は A_i です。

ある日、機器トラブルにより K 個のセンサーが故障し、計測値が正しく取得できなくなってしまいました。故障したセンサーの番号は B_1, B_2, \ldots, B_K です。これらは昇順とは限りません。

青木君は故障したセンサーのデータを補完するため、各故障センサーに対して推定値を入力しました。故障したセンサー B_j に対して青木君が入力した推定値は C_j です。

補完後の i 番目のセンサーの値を V_i とします。V_i は以下のように定まります。

  • センサー i が故障していない場合(すなわち、iB_1, B_2, \ldots, B_K のいずれとも等しくない場合)、V_i = A_i
  • センサー i が故障している場合(すなわち、i = B_j となる j が存在する場合)、V_i = C_j

高橋君はシステム全体のデータの滑らかさを評価するため、隣接するセンサー間の値の差の絶対値の総和である「変動量」を計算することにしました。変動量は

\sum_{i=1}^{N-1} |V_{i+1} - V_i|

と定義されます。

変動量を求めてください。

なお、入力では全センサーの正常時の計測値 A_1, A_2, \ldots, A_N が与えられますが、故障したセンサーについては正常時の計測値ではなく推定値が用いられることに注意してください。

制約

  • 2 \leq N \leq 200000
  • 1 \leq K \leq N
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq B_j \leq N (1 \leq j \leq K)
  • B_1, B_2, \ldots, B_K はすべて異なる
  • 1 \leq C_j \leq 10^9 (1 \leq j \leq K)
  • 入力はすべて整数である

入力

N K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_K
C_1 C_2 \ldots C_K
  • 1 行目には、センサーの総数を表す整数 N と、故障したセンサーの数を表す整数 K が、スペース区切りで与えられる。
  • 2 行目には、各センサーの正常時の計測値 A_1, A_2, \ldots, A_N がスペース区切りで与えられる。
  • 3 行目には、故障したセンサーの番号 B_1, B_2, \ldots, B_K がスペース区切りで与えられる。
  • 4 行目には、青木君が入力した推定値 C_1, C_2, \ldots, C_K がスペース区切りで与えられる。C_j は故障したセンサー B_j に対応する推定値である。

出力

変動量を 1 行で出力せよ。


入力例 1

5 2
10 20 30 40 50
2 4
25 35

出力例 1

40

入力例 2

4 1
100 200 300 400
3
500

出力例 2

500

入力例 3

10 3
5 12 8 20 15 3 18 7 25 10
3 7 10
10 20 6

出力例 3

103

入力例 4

15 5
1000000000 500000000 300000000 700000000 100000000 900000000 200000000 800000000 400000000 600000000 150000000 850000000 50000000 950000000 250000000
5 2 11 8 14
999999999 1 777777777 123456789 987654321

出力例 4

6078395060

入力例 5

2 2
1 1000000000
2 1
500000000 500000000

出力例 5

0

Score : 266 pts

Problem Statement

Takahashi manages an observation system consisting of N sensors arranged in a row. Each sensor is numbered from 1 to N, and the normal measurement value of the i-th sensor is A_i.

One day, due to an equipment malfunction, K sensors broke down and their measurement values could no longer be correctly obtained. The numbers of the broken sensors are B_1, B_2, \ldots, B_K. These are not necessarily in ascending order.

To fill in the data for the broken sensors, Aoki entered an estimated value for each broken sensor. The estimated value that Aoki entered for broken sensor B_j is C_j.

Let V_i denote the value of the i-th sensor after the data completion. V_i is determined as follows:

  • If sensor i is not broken (i.e., i is not equal to any of B_1, B_2, \ldots, B_K), then V_i = A_i.
  • If sensor i is broken (i.e., there exists a j such that i = B_j), then V_i = C_j.

To evaluate the smoothness of the entire system's data, Takahashi decided to calculate the "total variation," which is the sum of absolute differences between values of adjacent sensors. The total variation is defined as

\sum_{i=1}^{N-1} |V_{i+1} - V_i|

Find the total variation.

Note that while the normal measurement values A_1, A_2, \ldots, A_N of all sensors are given in the input, the estimated values are used instead of the normal measurement values for broken sensors.

Constraints

  • 2 \leq N \leq 200000
  • 1 \leq K \leq N
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq B_j \leq N (1 \leq j \leq K)
  • B_1, B_2, \ldots, B_K are all distinct
  • 1 \leq C_j \leq 10^9 (1 \leq j \leq K)
  • All input values are integers

Input

N K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_K
C_1 C_2 \ldots C_K
  • The first line contains two space-separated integers: N, the total number of sensors, and K, the number of broken sensors.
  • The second line contains the normal measurement values A_1, A_2, \ldots, A_N of each sensor, separated by spaces.
  • The third line contains the numbers B_1, B_2, \ldots, B_K of the broken sensors, separated by spaces.
  • The fourth line contains the estimated values C_1, C_2, \ldots, C_K entered by Aoki, separated by spaces. C_j is the estimated value corresponding to broken sensor B_j.

Output

Output the total variation in a single line.


Sample Input 1

5 2
10 20 30 40 50
2 4
25 35

Sample Output 1

40

Sample Input 2

4 1
100 200 300 400
3
500

Sample Output 2

500

Sample Input 3

10 3
5 12 8 20 15 3 18 7 25 10
3 7 10
10 20 6

Sample Output 3

103

Sample Input 4

15 5
1000000000 500000000 300000000 700000000 100000000 900000000 200000000 800000000 400000000 600000000 150000000 850000000 50000000 950000000 250000000
5 2 11 8 14
999999999 1 777777777 123456789 987654321

Sample Output 4

6078395060

Sample Input 5

2 2
1 1000000000
2 1
500000000 500000000

Sample Output 5

0
B - 最寄りの避難所

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 333

問題文

高橋君の住む街には、東西に伸びる 1 本の大通りがあります。この大通りは数直線とみなすことができ、西側が座標の小さい方向、東側が座標の大きい方向に対応します。

この大通り上には N 軒の家が建っており、西側から順に家 1 , 家 2 , \ldots , 家 N と番号が振られています。家 i は座標 X_i の位置にあり、どの 2 軒の家も異なる位置に建っています( X_1 < X_2 < \cdots < X_N )。

また、この大通り上には M 箇所の避難所が設置されており、西側から順に避難所 1 , 避難所 2 , \ldots , 避難所 M と番号が振られています。避難所 j は座標 P_j の位置にあり、どの 2 箇所の避難所も異なる位置に設置されています( P_1 < P_2 < \cdots < P_M )。

なお、家の座標と避難所の座標が一致する場合もあります。

市の防災担当である高橋君は、災害時に各家の住民が最も近い避難所へ避難できるよう、それぞれの家から最も近い避難所までの距離を調べることにしました。ここで、座標 a の地点から座標 b の地点までの距離は |a - b| で表されます。

各家 i1 \leq i \leq N )について、家 i から最も近い避難所までの距離、すなわち \displaystyle \min_{1 \leq j \leq M} |X_i - P_j| を求めてください。最も近い避難所が複数ある場合でも、距離は一意に定まります。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 2 \times 10^5
  • 0 \leq X_i \leq 10^91 \leq i \leq N
  • 0 \leq P_j \leq 10^91 \leq j \leq M
  • X_1 < X_2 < \cdots < X_N
  • P_1 < P_2 < \cdots < P_M
  • 入力はすべて整数である

入力

N M
X_1 X_2 \ldots X_N
P_1 P_2 \ldots P_M
  • 1 行目には、家の軒数を表す整数 N と、避難所の箇所数を表す整数 M が、空白区切りで与えられる。
  • 2 行目には、各家の座標を表す整数 X_1, X_2, \ldots, X_N が、空白区切りで与えられる。
  • 3 行目には、各避難所の座標を表す整数 P_1, P_2, \ldots, P_M が、空白区切りで与えられる。

出力

N 行にわたって出力せよ。 i 行目( 1 \leq i \leq N )には、家 i から最も近い避難所までの距離を整数で出力せよ。


入力例 1

3 2
1 5 9
3 8

出力例 1

2
2
1

入力例 2

5 3
2 10 25 40 60
5 30 50

出力例 2

3
5
5
10
10

入力例 3

10 4
3 15 27 48 55 72 88 100 130 200
10 50 90 150

出力例 3

7
5
17
2
5
18
2
10
20
50

Score : 333 pts

Problem Statement

In the town where Takahashi lives, there is a single main street running from east to west. This main street can be regarded as a number line, where the west side corresponds to the direction of smaller coordinates and the east side corresponds to the direction of larger coordinates.

There are N houses built along this main street, numbered house 1, house 2, \ldots, house N from west to east. House i is located at coordinate X_i, and no two houses are built at the same position (X_1 < X_2 < \cdots < X_N).

There are also M shelters set up along this main street, numbered shelter 1, shelter 2, \ldots, shelter M from west to east. Shelter j is located at coordinate P_j, and no two shelters are set up at the same position (P_1 < P_2 < \cdots < P_M).

Note that a house and a shelter may be located at the same coordinate.

Takahashi, who is in charge of disaster prevention for the city, decided to determine the distance from each house to its nearest shelter so that residents of each house can evacuate to the nearest shelter in case of a disaster. Here, the distance from a point at coordinate a to a point at coordinate b is given by |a - b|.

For each house i (1 \leq i \leq N), find the distance from house i to the nearest shelter, that is, \displaystyle \min_{1 \leq j \leq M} |X_i - P_j|. Even if there are multiple nearest shelters, the distance is uniquely determined.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 2 \times 10^5
  • 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
  • 0 \leq P_j \leq 10^9 (1 \leq j \leq M)
  • X_1 < X_2 < \cdots < X_N
  • P_1 < P_2 < \cdots < P_M
  • All inputs are integers

Input

N M
X_1 X_2 \ldots X_N
P_1 P_2 \ldots P_M
  • The first line contains an integer N representing the number of houses and an integer M representing the number of shelters, separated by a space.
  • The second line contains integers X_1, X_2, \ldots, X_N representing the coordinates of each house, separated by spaces.
  • The third line contains integers P_1, P_2, \ldots, P_M representing the coordinates of each shelter, separated by spaces.

Output

Print N lines. On the i-th line (1 \leq i \leq N), print the distance from house i to its nearest shelter as an integer.


Sample Input 1

3 2
1 5 9
3 8

Sample Output 1

2
2
1

Sample Input 2

5 3
2 10 25 40 60
5 30 50

Sample Output 2

3
5
5
10
10

Sample Input 3

10 4
3 15 27 48 55 72 88 100 130 200
10 50 90 150

Sample Output 3

7
5
17
2
5
18
2
10
20
50
C - 水やりの記録

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 366

問題文

高橋君は学校の園芸委員会に所属しており、花壇の管理を担当しています。

花壇には N 本の植物が一列に並んでおり、先頭から順に植物 1, 植物 2, \ldots, 植物 N と番号が付けられています。各植物 i (1 \leq i \leq N) は、初期の水分量として整数値 A_i を持っています。高橋君はじょうろを使って、これらの植物に水やりを行います。

高橋君は合計 M 回の水やりを行います。j 回目 (1 \leq j \leq M) の水やりでは、植物 L_j から植物 R_j まで(両端含む)の連続した範囲のすべての植物に水を与え、対象となった各植物の水分量を 1 ずつ増加させます。ある植物が複数回の水やりの対象となった場合、対象となった回数だけ水分量が増加します。

すべての水やりが終わった後、水分量が K 以上になった植物の本数を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 2 \times 10^5
  • 1 \leq K \leq 10^9
  • 0 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq L_j \leq R_j \leq N (1 \leq j \leq M)
  • 入力はすべて整数である

入力

N M K
A_1 A_2 \ldots A_N
L_1 R_1
L_2 R_2
\vdots
L_M R_M
  • 1 行目には、植物の本数を表す整数 N、水やりの回数を表す整数 M、水分量の閾値を表す整数 K が、スペース区切りで与えられる。
  • 2 行目には、各植物の初期の水分量を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
  • 続く M 行にわたり、各水やりの対象範囲が与えられる。
  • 2 + j 行目 (1 \leq j \leq M) には、j 回目の水やりの対象となる植物の番号の範囲を表す整数 L_jR_j が、スペース区切りで与えられる。

出力

すべての水やりが終わった後、水分量が K 以上になった植物の本数を 1 行で出力せよ。


入力例 1

5 3 3
1 2 0 1 3
1 3
2 4
1 5

出力例 1

5

入力例 2

8 4 5
3 1 4 0 2 5 1 0
1 4
3 6
2 5
6 8

出力例 2

2

入力例 3

10 5 1000000000
999999999 0 999999998 500000000 0 1000000000 999999997 0 999999999 0
1 3
1 1
6 7
7 10
3 9

出力例 3

5

Score : 366 pts

Problem Statement

Takahashi is a member of his school's gardening committee and is in charge of managing the flower bed.

The flower bed contains N plants arranged in a row, numbered Plant 1, Plant 2, \ldots, Plant N from the front. Each plant i (1 \leq i \leq N) has an initial moisture level of integer value A_i. Takahashi uses a watering can to water these plants.

Takahashi performs a total of M waterings. In the j-th watering (1 \leq j \leq M), he waters all plants in the contiguous range from Plant L_j to Plant R_j (inclusive), increasing the moisture level of each targeted plant by 1. If a plant is targeted by multiple waterings, its moisture level increases by the number of times it was targeted.

After all waterings are completed, find the number of plants whose moisture level is at least K.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 2 \times 10^5
  • 1 \leq K \leq 10^9
  • 0 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq L_j \leq R_j \leq N (1 \leq j \leq M)
  • All input values are integers

Input

N M K
A_1 A_2 \ldots A_N
L_1 R_1
L_2 R_2
\vdots
L_M R_M
  • The first line contains three space-separated integers: N representing the number of plants, M representing the number of waterings, and K representing the moisture threshold.
  • The second line contains space-separated integers A_1, A_2, \ldots, A_N representing the initial moisture level of each plant.
  • The following M lines specify the target range of each watering.
  • The (2 + j)-th line (1 \leq j \leq M) contains two space-separated integers L_j and R_j representing the range of plant numbers targeted by the j-th watering.

Output

Print in one line the number of plants whose moisture level is at least K after all waterings are completed.


Sample Input 1

5 3 3
1 2 0 1 3
1 3
2 4
1 5

Sample Output 1

5

Sample Input 2

8 4 5
3 1 4 0 2 5 1 0
1 4
3 6
2 5
6 8

Sample Output 2

2

Sample Input 3

10 5 1000000000
999999999 0 999999998 500000000 0 1000000000 999999997 0 999999999 0
1 3
1 1
6 7
7 10
3 9

Sample Output 3

5
D - 救急搬送ネットワーク

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 400

問題文

ある地域には N 個の拠点があり、それぞれ 1 から N までの番号が付けられています。拠点間は M 本の道路で結ばれており、i 番目の道路は拠点 U_i と拠点 V_i を双方向に結んでいます。各道路には移動コスト W_i が設定されており、どちらの方向に通っても同じコストがかかります。

高橋君はこの地域の救急医療センター(拠点 S)に勤務しています。災害が発生した際、救急医療センターから各拠点へ医療物資を届ける必要があります。

ここで、拠点 S から拠点 vv \neq S)への経路とは、拠点の列 S = p_0, p_1, \dots, p_k = vk \geq 1)であって、連続する各拠点の組 (p_{j}, p_{j+1})0 \leq j \leq k-1)を結ぶ道路が存在するものを指します。ただし、同じ拠点や同じ道路を複数回通ってもよいものとします。この経路の移動コストとは、経路上で通る各道路の移動コストの総和、すなわち \displaystyle\sum_{j=0}^{k-1}(拠点 p_j と拠点 p_{j+1} を結ぶ道路の移動コスト) です。

拠点 vv \neq S)について、拠点 S から拠点 v への経路が 1 つ以上存在するとき、拠点 v は拠点 S から到達可能であるといいます。道路網の構造上、拠点 S から到達できない拠点が存在する場合もあります。

高橋君は、拠点 S から到達可能な全ての拠点に対して、最小の移動コストで医療物資を届けたいと考えています。拠点 S から到達可能な各拠点 vv \neq S)について、拠点 S から拠点 v への全ての経路の移動コストのうち最小のものを d(v) とします。

拠点 S から到達可能な全ての拠点 vv \neq S)に対する d(v) の総和を求めてください。拠点 S 以外に到達可能な拠点が存在しない場合、総和は 0 とします。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq 2 \times 10^5
  • 1 \leq S \leq N
  • 1 \leq U_i, V_i \leq N1 \leq i \leq M
  • U_i \neq V_i1 \leq i \leq M
  • 1 \leq W_i \leq 10^41 \leq i \leq M
  • 同じ拠点の組 \{U_i, V_i\} を結ぶ道路は高々 1 本である(すなわち、i \neq j ならば \{U_i, V_i\} \neq \{U_j, V_j\}
  • 入力は全て整数である

入力

N M S
U_1 V_1 W_1
U_2 V_2 W_2
\vdots
U_M V_M W_M
  • 1 行目には、拠点の数 N、道路の数 M、救急医療センターの拠点番号 S が、スペース区切りで与えられる。
  • 続く M 行のうち i 行目(1 \leq i \leq M)には、i 番目の道路が結ぶ 2 つの拠点の番号 U_i, V_i と、その道路の移動コスト W_i がスペース区切りで与えられる。

出力

拠点 S から到達可能な全ての拠点 vv \neq S)に対する d(v) の総和を 1 行で出力してください。


入力例 1

4 4 1
1 2 3
1 3 5
2 3 1
2 4 6

出力例 1

16

入力例 2

5 3 1
1 2 2
2 3 3
4 5 1

出力例 2

7

入力例 3

8 10 1
1 2 1
1 3 4
2 3 2
2 4 7
3 5 3
4 5 1
4 6 5
5 7 2
6 8 3
7 8 4

出力例 3

49

入力例 4

15 20 1
1 2 3
1 3 7
2 4 2
2 5 8
3 5 1
3 6 4
4 7 5
5 8 3
6 8 2
6 9 6
7 10 1
8 10 4
8 11 7
9 12 3
10 11 2
10 13 6
11 14 4
12 14 5
13 15 3
14 15 2

出力例 4

169

入力例 5

1 0 1

出力例 5

0

Score : 400 pts

Problem Statement

A certain region has N bases, numbered from 1 to N. The bases are connected by M roads, where the i-th road bidirectionally connects base U_i and base V_i. Each road has a travel cost W_i, which is the same regardless of the direction of travel.

Takahashi works at the emergency medical center (base S) in this region. When a disaster occurs, medical supplies need to be delivered from the emergency medical center to each base.

Here, a path from base S to base v (v \neq S) is a sequence of bases S = p_0, p_1, \dots, p_k = v (k \geq 1) such that for each pair of consecutive bases (p_{j}, p_{j+1}) (0 \leq j \leq k-1), there exists a road connecting them. Note that the same base or the same road may be visited multiple times. The travel cost of this path is the sum of the travel costs of each road traversed along the path, that is, \displaystyle\sum_{j=0}^{k-1}(travel cost of the road connecting base p_j and base p_{j+1}).

For a base v (v \neq S), if there exists at least one path from base S to base v, then base v is said to be reachable from base S. Due to the structure of the road network, there may exist bases that are not reachable from base S.

Takahashi wants to deliver medical supplies to all bases reachable from base S with minimum travel cost. For each base v (v \neq S) reachable from base S, let d(v) denote the minimum travel cost among all paths from base S to base v.

Find the sum of d(v) over all bases v (v \neq S) reachable from base S. If there are no reachable bases other than base S, the sum is 0.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq 2 \times 10^5
  • 1 \leq S \leq N
  • 1 \leq U_i, V_i \leq N (1 \leq i \leq M)
  • U_i \neq V_i (1 \leq i \leq M)
  • 1 \leq W_i \leq 10^4 (1 \leq i \leq M)
  • There is at most one road connecting the same pair of bases \{U_i, V_i\} (that is, if i \neq j then \{U_i, V_i\} \neq \{U_j, V_j\})
  • All input values are integers

Input

N M S
U_1 V_1 W_1
U_2 V_2 W_2
\vdots
U_M V_M W_M
  • The first line contains the number of bases N, the number of roads M, and the base number of the emergency medical center S, separated by spaces.
  • The i-th of the following M lines (1 \leq i \leq M) contains the numbers of the two bases U_i, V_i connected by the i-th road, and the travel cost W_i of that road, separated by spaces.

Output

Print in one line the sum of d(v) over all bases v (v \neq S) reachable from base S.


Sample Input 1

4 4 1
1 2 3
1 3 5
2 3 1
2 4 6

Sample Output 1

16

Sample Input 2

5 3 1
1 2 2
2 3 3
4 5 1

Sample Output 2

7

Sample Input 3

8 10 1
1 2 1
1 3 4
2 3 2
2 4 7
3 5 3
4 5 1
4 6 5
5 7 2
6 8 3
7 8 4

Sample Output 3

49

Sample Input 4

15 20 1
1 2 3
1 3 7
2 4 2
2 5 8
3 5 1
3 6 4
4 7 5
5 8 3
6 8 2
6 9 6
7 10 1
8 10 4
8 11 7
9 12 3
10 11 2
10 13 6
11 14 4
12 14 5
13 15 3
14 15 2

Sample Output 4

169

Sample Input 5

1 0 1

Sample Output 5

0
E - 感染シミュレーション

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 466

問題文

高橋君は、ある村の保健担当者です。村には N 人の住民が一列に並んで暮らしており、左から順に 1 から N までの番号が付けられています。

各住民 i には免疫力を表す整数 H_i が定められています。免疫力が 0 以下の住民は感染状態です。一度感染状態になった住民は、その後も感染状態のままです。

感染はラウンド制で広がります。はじめ、H_i \leq 0 である住民は感染状態であり、これをラウンド 0 の感染状態とします。

ラウンド 1,2,\ldots では、次の処理を順に行います。

  • そのラウンドの開始時点で感染状態にあるすべての住民が、自分に隣接する住民(番号が 1 だけ異なる住民)の免疫力をそれぞれ D だけ減少させます。
  • ある住民の左右両方の隣人が感染状態である場合、その住民の免疫力は合計で 2D 減少します。
  • 免疫力が 0 以下になった住民は、このラウンドの終了時に新たに感染状態になります。
  • このラウンドで新たに感染状態になった住民が 1 人もいなかった場合、伝播はただちに終了し、それ以降のラウンドは行われません。

高橋君は、伝播が終了した時点で感染状態になっている住民の人数を求めたいです。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq D \leq 10^9
  • -10^9 \leq H_i \leq 10^9 (1 \leq i \leq N)
  • 入力はすべて整数である

入力

N D
H_1 H_2 \ldots H_N

出力

伝播が終了した時点で感染状態になっている住民の人数を 1 行で出力せよ。


入力例 1

7 3
2 0 5 4 8 0 2

出力例 1

7

入力例 2

5 2
10 -1 10 10 10

出力例 2

1

入力例 3

15 6
18 11 -4 20 5 35 7 14 28 0 16 9 40 3 22

出力例 3

2

入力例 4

50 10
15 28 -3 45 12 80 5 70 35 -1 60 22 11 95 40 8 75 18 6 55 30 -20 90 4 14 100 65 25 9 85 13 7 120 50 -5 33 44 2 68 16 27 0 58 73 19 81 3 39 10 92

出力例 4

5

入力例 5

1 1000000000
1000000000

出力例 5

0

Score : 466 pts

Problem Statement

Takahashi is a health official in a certain village. In this village, N residents live in a single row, numbered 1 to N from left to right.

Each resident i has an integer H_i representing their immunity. A resident whose immunity is 0 or less is in an infected state. Once a resident becomes infected, they remain infected.

The infection spreads in rounds. Initially, residents with H_i \leq 0 are infected, which we consider as the infected state at Round 0.

In Round 1, 2, \ldots, the following processes are performed in order:

  • Every resident who is infected at the start of that round decreases the immunity of their adjacent residents (residents whose indices differ by exactly 1) by D each.
  • If both the left and right neighbors of a resident are infected, that resident's immunity decreases by 2D in total.
  • Residents whose immunity becomes 0 or less will newly become infected at the end of this round.
  • If no residents newly become infected during this round, the spread terminates immediately, and no subsequent rounds are conducted.

Takahashi wants to find the number of residents who are infected when the spread ends.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq D \leq 10^9
  • -10^9 \leq H_i \leq 10^9 (1 \leq i \leq N)
  • All input values are integers.

Input

N D
H_1 H_2 \ldots H_N

Output

Print the number of residents who are infected when the spread ends in a single line.


Sample Input 1

7 3
2 0 5 4 8 0 2

Sample Output 1

7

Sample Input 2

5 2
10 -1 10 10 10

Sample Output 2

1

Sample Input 3

15 6
18 11 -4 20 5 35 7 14 28 0 16 9 40 3 22

Sample Output 3

2

Sample Input 4

50 10
15 28 -3 45 12 80 5 70 35 -1 60 22 11 95 40 8 75 18 6 55 30 -20 90 4 14 100 65 25 9 85 13 7 120 50 -5 33 44 2 68 16 27 0 58 73 19 81 3 39 10 92

Sample Output 4

5

Sample Input 5

1 1000000000
1000000000

Sample Output 5

0