The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≤ i ≤ n) day, the price for one barrel of honey is going to is x_{i} kilos of raspberry.

Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for c kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day d (1 ≤ d < n), lent a barrel of honey and immediately (on day d) sell it according to a daily exchange rate. The next day (d + 1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day d + 1) give his friend the borrowed barrel of honey as well as c kilograms of raspberry for renting the barrel.

The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.


-----Input-----

The first line contains two space-separated integers, n and c (2 ≤ n ≤ 100, 0 ≤ c ≤ 100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.

The second line contains n space-separated integers x_1, x_2, ..., x_{n} (0 ≤ x_{i} ≤ 100), the price of a honey barrel on day i.


-----Output-----

Print a single integer — the answer to the problem.


-----Examples-----
Input
5 1
5 10 7 3 20

Output
3

Input
6 2
100 1 10 40 10 40

Output
97

Input
3 0
1 2 3

Output
0



-----Note-----

In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.

In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97.

Difficulty: EASY
Tags: Complete search

Implementation

Greedy algorithms
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
(n, c) = map(int, input().split())
arr = list(map(int, input().split()))
res = c
for i in range(n - 1):
	res = max(res, arr[i] - arr[i + 1])
res = max(0, res - c)
print(res)


(n, c) = map(int, input().split())
x = list(map(int, input().split()))
ma = 0
for i in range(0, n - 1):
	ma = max(ma, x[i] - x[i + 1] - c)
print(ma)


a = int(input().split()[1])
s = input().split()
d = []
for i in range(len(s) - 1):
	d.append(int(s[i]) - int(s[i + 1]))
n = max(d) - a
if n <= 0:
	print(0)
else:
	print(n)


(n, c) = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
r = 0
for i in range(n - 1):
	if c < x[i] and x[i] > x[i + 1]:
		if x[i] - x[i + 1] > r:
			r = x[i] - x[i + 1]
if r < c:
	print(0)
else:
	print(r - c)


s = input('')
(n, c) = s.split(' ')
n = int(n)
c = int(c)
s1 = input('')
l = s1.split(' ')
l1 = []
l = list(map(int, l))
for i in range(n - 1):
	if l[i + 1] < l[i]:
		l1.append(l[i] - l[i + 1])
if len(l1) == 0:
	print('0')
elif c > max(l1):
	print('0')
else:
	print(max(l1) - c)


(n, b) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
	ans = max(ans, l[i] - l[i + 1] - b)
print(ans)


(n, c) = [v for v in map(int, input().split())]
p = [v for v in map(int, input().split())]
profit = lambda i: p[i] - p[i + 1] - c
max_profit = 0
for i in range(n - 1):
	pr = profit(i)
	if pr > max_profit:
		max_profit = pr
print(max_profit)


temp = input()
temp = temp.split()
n = int(temp[0])
c = int(temp[1])
price = input()
price = price.split()
price = [int(x) for x in price]
difference = 0
index = 0
for x in range(len(price) - 1):
	if price[x] - price[x + 1] > difference:
		index = x
		difference = price[x] - price[x + 1]
if difference == 0:
	print('0')
elif price[index] - price[index + 1] - c >= 0:
	print(price[index] - price[index + 1] - c)
else:
	print('0')


def solve(n, c, arr):
	max_diff = 0
	for i in range(n - 1):
		diff = arr[i] - arr[i + 1]
		if diff > max_diff:
			max_diff = diff
	return max(0, max_diff - c)

def main():
	(n, c) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	print(solve(n, c, arr))
main()


(n, c) = map(int, input().split())
l = list(map(int, input().split()))
r = 0
for i in range(n - 1):
	if l[i] - l[i + 1] > r:
		r = l[i] - l[i + 1]
if r > c:
	print(r - c)
else:
	print('0')


(n, c) = map(int, input().split())
a = list(map(int, input().split()))
t = 0
for i in range(n - 1):
	t = max(t, a[i] - a[i + 1] - c)
print(max(t, 0))


(n, c) = map(int, input().split())
x = list(map(int, input().split()))
a = []
for i in range(n - 1):
	a.append(x[i] - x[i + 1] - c)
print(max(a) if max(a) > 0 else 0)


(n, c) = list(map(int, input().split()))
x = list(map(int, input().split()))
profit = [x[i] - c - x[i + 1] for i in range(len(x) - 1)]
print(max(0, max(profit)))


def solve():
	(n, c) = map(int, input().split())
	ls = list(map(int, input().split()))
	price = []
	for i in range(len(ls) - 1):
		price.append(ls[i] - ls[i + 1])
	profit = max(price) - c
	if profit > 0:
		print(profit)
	else:
		print(0)
solve()


from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
(n, m) = M()
a = LI()
ans = 0
for i in range(n - 1):
	ans = max(ans, a[i] - a[i + 1] - m)
print(ans)


(n, c) = list(map(int, input().split()))
p = list(map(int, input().split()))
m = 0
for i in range(n - 1):
	if p[i] > p[i + 1]:
		m = max(m, p[i] - p[i + 1] - c)
print(m)


(n, c) = input().split(' ')
n = int(n)
c = int(c)
max = 0
a = input().split(' ')
for i in range(n):
	a[i] = int(a[i])
for i in range(n - 1):
	if a[i] - a[i + 1] - c > 0:
		if a[i] - a[i + 1] - c > max:
			max = a[i] - a[i + 1] - c
print(max)


(n, c) = map(int, input().split())
d = list(map(int, input().split()))
if d.index(min(d)) == 0:
	print('0')
else:
	w = []
	for i in range(len(d) - 1):
		w.append(d[i] - d[i + 1])
	print(max(0, max(w) - c))


(n, b) = list(map(int, input().split()))
x = list(map(int, input().split()))
ans = []
for i in range(n - 1):
	if x[i] >= x[i + 1]:
		ans.append(x[i] - x[i + 1])
if len(ans) == 0:
	print(0)
else:
	ans = max(ans) - b
	if ans <= 0:
		print(0)
	else:
		print(ans)


(n, c) = list(map(int, input().split()))
price = list(map(int, input().split()))
profit = 0
for i in range(len(price) - 1):
	t = price[i] - price[i + 1] - c
	if t > profit:
		profit = t
print(profit)


a = list(map(int, input().split()))
(n, c) = (a[0], a[1])
b = list(map(int, input().split()))
max_r = 0
for i in range(0, n - 1):
	if b[i] - b[i + 1] > max_r:
		max_r = b[i] - b[i + 1]
		p1 = b[i]
		p2 = b[i + 1]
ans = max_r - c
if ans > 0:
	print(ans)
else:
	print(0)


(n, c) = str(input()).split()
n = int(n)
c = int(c)
line = str(input()).split()
line = [int(it) for it in line]
tar = 0
for i in range(n - 1):
	tar = max(line[i] - line[i + 1], tar)
print(max(tar - c, 0))


(n, k) = map(int, input().split())
a = list(map(int, input().strip().split()))
b = []
for _ in range(len(a) - 1):
	b.append(a[_] - a[_ + 1])
print(max(b) - k if max(b) - k > 0 else 0)


(a, b) = map(int, input().split())
s = list(map(int, input().split()))
x = 0
razn = 0
for i in range(a - 1):
	if s[i] > s[i + 1]:
		x = s[i] - s[i + 1]
		razn = max(razn, x)
print(max(razn - b, 0))


import sys
(n, c) = map(int, sys.stdin.readline().split())
x = list(map(int, sys.stdin.readline().split()))
a = max([x[i] - x[i + 1] for i in range(n - 1)])
print(max(a - c, 0))


a = []
a = input().split()
n = int(a[0])
c = int(a[1])
x = []
x = input().split()
for i in range(0, n, 1):
	x[i] = int(x[i])
profit = []
for i in range(0, n - 1, 1):
	p = x[i] - x[i + 1] - c
	if p > 0:
		profit.append(p)
	else:
		profit.append(0)
print(max(profit))


(n, c) = map(int, input().split())
m = 0
l = list(map(int, input().split()))
for i in range(n - 1):
	m = max(m, l[i] - l[i + 1] - c)
print(m)


def inp():
	return input()

def si():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def solve():
	(n, m) = mi()
	arr = li()
	ans = 0
	for i in range(1, n):
		ans = max(ans, arr[i - 1] - arr[i] - m)
	print(ans)
solve()


(n, c) = map(int, input().split())
ll = list(map(int, input().split()))
ll1 = []
for i in range(n - 1):
	ll1.append(ll[i] - ll[i + 1] - c)
if max(ll1) <= 0:
	print(0)
else:
	print(max(ll1))


(a, b) = list(map(int, input().split()))
c = list(map(int, input().split()))
d = max((c[i] - b - c[i + 1] for i in range(len(c) - 1)))
if d >= 0:
	print(d)
else:
	print(0)


(n, c) = map(int, input().split())
a = [int(x) for x in input().split()]
t = 0
for i in range(n - 1):
	if t < a[i] - a[i + 1]:
		t = a[i] - a[i + 1]
if t == 0 or t < c:
	print(0)
else:
	print(t - c)


(n, c) = map(int, input().split())
arr = list(map(int, input().split()))
max = 0
for i in range(1, len(arr)):
	if arr[i - 1] - arr[i] > max:
		max = arr[i - 1] - arr[i]
print(max - c) if max - c > 0 else print(0)


arr1 = input().split(' ')
days = int(arr1[0])
kilos = int(arr1[1])
raspberryMaxVal = 0
prices = input().split(' ')
kilos = int(kilos)
days = int(days)
for i in range(0, days - 1):
	currentVal = int(prices[i]) - int(prices[i + 1]) - kilos
	if currentVal < 0:
		continue
	elif currentVal > raspberryMaxVal:
		raspberryMaxVal = currentVal
print(raspberryMaxVal)


(n, c) = input().split(' ')
n = int(n)
c = int(c)
x = [int(i) for i in input().split(' ')]
f = False
old = x[0]
answer = 0
for new in x:
	if f == False:
		f = True
	answer = max(answer, old - new - c)
	old = new
if answer < 0:
	print(answer)
	exit(0)
print(answer)


(n, c) = map(int, input().split())
ans = 0
l1 = list(map(int, input().split()))
for i in range(n - 1):
	ans = max(ans, l1[i] - l1[i + 1] - c)
print(ans)


bot = True
r = lambda : map(int, input().split())
(d, b) = r()
l = list(r())
m = max((l[x] - l[x + 1] for x in range(d - 1))) - b
print(max(0, m))


(n, c) = map(int, input().split())
a = [int(i) for i in input().split()]
maxr = 0
ind = 0
for i in range(n - 1):
	if a[i] - a[i + 1] > maxr and a[i] - a[i + 1] - c > 0:
		maxr = a[i] - a[i + 1]
if maxr - c > 0:
	print(maxr - c)
else:
	print(0)


(n, c) = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
for i in range(n - 1):
	x[i] = x[i] - x[i + 1]
ans = max(x[:-1]) - c
if ans > 0:
	print(ans)
else:
	print(0)


(n, c) = list(map(int, input().split(' ')))
price_per_day = list(map(int, input().split(' ')))
profit = 0
for i in range(0, n - 1):
	earned = price_per_day[i] - price_per_day[i + 1] - c
	if earned > profit:
		profit = earned
if profit <= 0:
	print(0)
else:
	print(profit)


(n, c) = map(int, input().split())
p = list(map(int, input().split()))
t = 0
for x in range(n - 1):
	t = max(t, p[x] - p[x + 1] - c)
print(t)


(d, c) = map(int, input().split())
m = 0
ds = list(map(int, input().split()))
for i in range(d - 1):
	m = max(ds[i] - ds[i + 1], m)
if m - c > 0:
	print(m - c)
else:
	print(0)


(n, c) = list(map(int, input().split()))
A = list(map(int, input().split()))
best = 0
for i in range(n - 1):
	if A[i] - A[i + 1] > best:
		best = A[i] - A[i + 1]
print(max(0, best - c))


I = [int(i) for i in input().split()]
(n, c) = (I[0], I[1])
I = [int(i) for i in input().split()]
I_new = []
for i in range(1, n):
	I_new.append(I[i - 1] - I[i])
I_new.sort()
ans = I_new[-1] - c
if ans < 0:
	print(0)
else:
	print(ans)


(n, c) = map(int, input().split())
x = list(map(int, input().split()))
max_diff = -999999
for i in range(n - 1):
	if x[i] - x[i + 1] > max_diff:
		max_diff = x[i] - x[i + 1]
res = max_diff - c
if res < 0:
	res = 0
print(res)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
m = int(0)
for i in range(a - 1):
	if m < l[i] - l[i + 1] - b:
		m = l[i] - l[i + 1] - b
print(m)


(n, c) = map(int, input().split())
l = list(map(int, input().split()))
z = 0
for i in range(len(l) - 1):
	z = max(l[i] - l[i + 1], z)
print(max(z - c, 0))


(n, c) = map(int, input().split(' '))
l = input().split(' ')
l = [int(x) for x in l]
max = 0
m = 0
for i in range(n - 1):
	if l[i] - l[i + 1] > max:
		max = l[i] - l[i + 1]
		m = i
if max - c > 0:
	print(max - c)
else:
	print(0)


(n, c) = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
dd = [0] * (n - 1)
for i in range(0, n - 1):
	dd[i] = d[i] - d[i + 1]
print(max(0, max(dd) - c))


(n, v) = map(int, input().split())
l = list(map(int, input().split()))
ma = 0
for i in range(n - 1):
	if l[i] - v - l[i + 1] > ma:
		ma = l[i] - v - l[i + 1]
print(ma)


(n, c) = map(int, input().split())
x = list(map(int, input().split()))
l = []
for i in range(n - 1):
	l.append(x[i] - x[i + 1] - c)
l.append(0)
print(max(l))


(a, b) = map(int, input().split())
v = list(map(int, input().split()))
l = []
for i in range(len(v) - 1):
	l.append(v[i] - v[i + 1] - b)
print(max(l) if max(l) >= 0 else 0)


(n, c) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
ind = -1
maxi = 0
for i in range(n - 1):
	if arr[i] - arr[i + 1] > maxi:
		ind = i
		maxi = arr[i] - arr[i + 1]
if ind == -1:
	print(0)
else:
	print(max(0, arr[ind] - arr[ind + 1] - c))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
	if a[i] - a[i + 1] > ans:
		ans = a[i] - a[i + 1]
ans = ans - m
if ans < 0:
	ans = 0
print(ans)


(n, c) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
max_diff = 0
for i in range(n - 1):
	if l[i] - l[i + 1] > max_diff:
		max_diff = l[i] - l[i + 1]
print(max(0, max_diff - c))


def main():
	readData = lambda : map(int, input().split())
	(n, c) = readData()
	X = list(readData())
	ret = 0
	for i in range(n - 1):
		ret = max(ret, X[i] - X[i + 1] - c)
	print(ret)
main()


(n, c) = map(int, input().split())
l = list(map(int, input().split()))
d = []
for i in range(len(l) - 1):
	d.append(l[i] - l[i + 1] - c)
if max(d) > 0:
	print(max(d))
else:
	print('0')


(n, c) = list(map(int, input().split()))
arr = [int(i) for i in input().split()]
(i, r) = (0, 0)
for i in range(n - 1):
	if arr[i] - arr[i + 1] - c > r:
		r = arr[i] - arr[i + 1] - c
print(r)


def max_raspberry(n_days: int, lend_price: int, honey_prices: list) -> int:
	money = max((honey_prices[i] - honey_prices[i + 1] for i in range(n_days - 1)))
	if money < lend_price:
		return 0
	return money - lend_price
(n, c) = map(int, input().split())
x = [int(i) for i in input().split()]
print(max_raspberry(n, c, x))


l1 = [int(x) for x in input().split()]
(n, interest) = (l1[0], l1[1])
l2 = [int(x) for x in input().split()]
profits = [0]
for x in range(n - 1):
	targ = l2[x]
	profits.append(targ - l2[x + 1] - interest)
if max(profits) > 0:
	print(max(profits))
else:
	print(0)


x = input().split()
n = int(x[0])
c = int(x[1])
x = input().split()
m = 0
for i in range(n - 1):
	x[i] = int(x[i])
	x[i + 1] = int(x[i + 1])
	if x[i] >= x[i + 1] and x[i] - x[i + 1] - c > m:
		m = x[i] - x[i + 1] - c
print(m)


(n, c) = (int(x) for x in input().split())
p = [int(x) for x in input().split()]
val = 0
for i in range(1, n):
	cur = p[i - 1] - p[i] - c
	if cur > val:
		val = cur
print(val)


(X, Max, Days) = (list(map(int, input().split())), 0, list(map(int, input().split())))
for i in range(X[0] - 1):
	Max = max(Max, Days[i] - Days[i + 1])
print(max(Max - X[1], 0))


m = int(input().split()[1])
yarmarka = [int(x) for x in input().split()]
c = 0
d = 0
for i in range(len(yarmarka) - 1):
	d = yarmarka[i] - yarmarka[i + 1]
	if d >= c:
		c = d
if c - m <= 0:
	print(0)
else:
	print(c - m)


n = list(map(int, input().split()))
m = list(map(int, input().split()))
c = []
for i in range(len(m) - 1):
	ci = m[i] - m[i + 1]
	c.append(ci)
max_i = max(c)
max_m = max(max_i - n[1], 0)
print(max_m)


(n, c) = input().split()
(n, c) = (int(n), int(c))
lista = list(map(int, input().split()))
rasp = 0
inferno = []
guloso = 0
for x in range(len(lista) - 1):
	if lista[x] - c - lista[x + 1] >= guloso:
		guloso = lista[x] - c - lista[x + 1]
print(guloso)


(n, c) = map(int, input().split())
l = list(map(int, input().split()))
m = l[0] - l[1]
for i in range(1, n - 1):
	v = l[i] - l[i + 1]
	if v > m:
		m = v
d = m - c
print(d if d > 0 else 0)


(n, c) = map(int, input().split())
s = list(map(int, input().split()))
diff = 0
for i in range(n - 1):
	if s[i] - s[i + 1] > diff:
		diff = s[i] - s[i + 1]
if diff - c > 0:
	print(diff - c)
else:
	print(0)


(n, c) = map(int, input().split())
pric = [int(x) for x in input().split()]
diff = (pric[i - 1] - pric[i] for i in range(1, n))
print(max(0, max(diff) - c))


(x, y) = map(int, input().split())
li = list(map(int, input().split()))
max1 = 0
for i in range(x - 1):
	if max1 < li[i] - li[i + 1]:
		max1 = li[i] - li[i + 1]
if max1 - y >= 0:
	print(max1 - y)
else:
	print(0)


(n, c) = (int(i) for i in input().split())
days = [int(i) for i in input().split()]
(d1, d2) = (iter(days), iter(days))
next(d2)
max_earnings = 0
for (cost1, cost2) in zip(d1, d2):
	max_earnings = max(max_earnings, cost1 - cost2 - c)
print(max_earnings)


n = input()
n = n.split()
n[0] = int(n[0])
n[1] = int(n[1])
x = input()
x = x.split()
res = [0]
for i in range(n[0]):
	x[i] = int(x[i])
for i in range(n[0] - 1):
	if x[i] > x[i + 1]:
		res.append(x[i] - x[i + 1] - n[1])
print(max(res))


import array
(n, c) = map(int, input().split())
array = list(map(int, input().split()))
print(max([0] + [array[i] - array[i + 1] - c for i in range(n - 1)]))


(N, C) = map(int, input().split())
X = list(map(int, input().split()))
ans = -1
for i in range(N - 1):
	ans = max(ans, X[i] - X[i + 1] - C)
if ans < 0:
	ans = 0
print(ans)


(n, c) = [int(x) for x in input().split()]
prices = [int(x) for x in input().split()]
dif = prices[0] - prices[1]
for i in range(n - 1):
	if prices[i] - prices[i + 1] > dif:
		dif = prices[i] - prices[i + 1]
print(max(0, dif - c))


try:
	(n, c) = map(int, input().split())
	k = [int(i) for i in input().split()]
	a = []
	for i in range(n - 1):
		if k[i] <= k[i + 1]:
			a.append(0)
		else:
			a.append(k[i] - k[i + 1])
	if max(a) == 0 or max(a) < c:
		print(0)
	else:
		print(max(a) - c)
except:
	pass


x = input().split(' ')
array = input().split(' ')
friend = int(x[1])
possible = False
diff = 0
i = 1
while i < len(array):
	temp = int(array[i - 1]) - int(array[i])
	if temp > diff:
		diff = temp
		possible = True
	i += 1
if not possible:
	print(0)
elif diff - friend <= 0:
	print(0)
else:
	print(diff - friend)


n = input().split()
p = input().split()
k = []
for i in range(len(p) - 1):
	y = int(p[i]) - int(p[i + 1])
	k.append(y)
if abs(max(k)) == max(k) and max(k) > int(n[1]):
	print(max(k) - int(n[1]))
else:
	print(0)


val = [int(n) for n in input().split()]
n = val[0]
c = val[1]
days = [int(n) for n in input().split()]
result = 0
for i in range(1, n):
	if days[i - 1] > days[i]:
		result = max(result, days[i - 1] - days[i] - c)
print(result)


[n, c] = [int(x) for x in input().split(' ')]
l = [int(x) for x in input().split(' ')]
maxrasp = 0
for i in range(len(l)):
	if i != len(l) - 1 and l[i] - l[i + 1] > maxrasp:
		maxrasp = l[i] - l[i + 1]
k = maxrasp - c
if k < 0:
	print(0)
else:
	print(k)


(N, C) = map(int, input().split())
Nums = list(map(int, input().split()))
Max = 0
for i in range(N - 1):
	Max = max(Max, Nums[i] - Nums[i + 1] - C)
print(Max)


(n, c) = map(int, input().split())
array = list(map(int, input().split()))
a = [0]
for i in range(n - 1):
	if array[i] < array[i + 1]:
		continue
	elif array[i] == array[i + 1]:
		continue
	else:
		d = array[i] - array[i + 1]
		a.append(d)
if max(a) >= c:
	print(max(a) - c)
else:
	print('0')


import sys

def main():
	(n, c) = map(int, sys.stdin.readline().strip().split())
	a = list(map(int, sys.stdin.readline().strip().split()))
	m = 0
	for i in range(len(a) - 1):
		r = a[i] - a[i + 1] - c
		m = max(m, r)
	print(m)
main()


(n, c) = map(int, input().split())
v = list(map(int, input().split()))
ret = 0
for i in range(n - 1):
	ret = max(ret, v[i] - v[i + 1] - c)
print(ret)


(a, b) = map(int, input().split())
L = list(map(int, input().split()))
L = list(zip(L[:a - 1], L[1:]))
maxi = 0
for k in L:
	valor = k[0] - k[1] - b
	if valor > maxi:
		maxi = valor
print(maxi)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a)
max1 = 0
if a == b:
	print(0)
else:
	for i in range(0, n - 1):
		max1 = max(max1, a[i] - a[i + 1] - k)
	print(max1)


(n, c) = map(int, input().split())
l = list(map(int, input().split()))
length = len(l)
max_r = 0
for i in range(length - 1):
	if l[i] - l[i + 1] > max_r:
		max_r = l[i] - l[i + 1]
if max_r > c:
	print(max_r - c)
else:
	print(0)


def bear(lst, c):
	result = 0
	for i in range(len(lst)):
		if i > 0 and lst[i - 1] - lst[i] - c > result:
			result = lst[i - 1] - lst[i] - c
	return result
(n, C) = [int(j) for j in input().split()]
a = [int(x) for x in input().split()]
print(bear(a, C))


(n, c) = map(int, input().split())
x = list(map(int, input().split()))
y = []
for a in range(len(x) - 1):
	y.append(abs(x[a]) - abs(x[a + 1]))
maxi = y.index(max(y))
if x[maxi] - x[maxi + 1] - c <= 0:
	print(0)
else:
	print(x[maxi] - x[maxi + 1] - c)


(n, c) = map(int, input().split())
days = list(map(int, input().split()))
MAX = [0]
for i in range(len(days)):
	if i != len(days) - 1:
		if days[i + 1] < days[i]:
			MAX.append(days[i] - days[i + 1] - c)
print(max(MAX))


(n, c) = map(int, input().split())
a = list(map(int, input().split()))
res = 0
for i in range(n - 1):
	diff = a[i] - a[i + 1]
	if diff >= 0:
		res = max(diff, res)
ans = res - c
if res - c < 0:
	print(0)
else:
	print(res - c)


(n, c) = input().split()
n = int(n)
c = int(c)
l = list(map(int, input().split()))
mx = -100000
for i in range(n - 1):
	if l[i] > l[i + 1] and l[i] - l[i + 1] > mx:
		mx = l[i] - l[i + 1]
s = mx - c
print(s if s > 0 else 0)


I = lambda : map(int, input().split())
(n, c) = I()
a = [*I()]
print(max(0, *[x - y - c for (x, y) in zip(a, a[1:])]))


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = []
for i in range(len(b) - 1):
	c.append(b[i] - b[i + 1])
if max(c) - a[1] > 0:
	print(max(c) - a[1])
else:
	print(0)


s = [int(i) for i in input().split(' ')]
n = s[0]
c = s[1]
a = [int(i) for i in input().split(' ')]
k = -1
for i in range(n - 1):
	if a[i] - a[i + 1] > k:
		k = a[i] - a[i + 1]
if k == -1 or k - c < 0:
	print(0)
else:
	print(k - c)


import math

def solve(arr, n, c):
	mx = -math.inf
	for i in range(1, n):
		mx = max(mx, arr[i - 1] - arr[i])
	if mx > c:
		return mx - c
	else:
		return 0
(n, c) = list(map(int, input().strip().split()))
arr = list(map(int, input().strip().split()))
result = solve(arr, n, c)
print(result)


def get_int():
	return map(int, input().split())
(n, c) = get_int()
x = list(get_int()) + [1000]
print(max(0, max([x[i] - x[i + 1] for i in range(len(x) - 1)]) - c))


def solve(lst, n):
	pass
(n, p) = map(int, input().split())
lst = list(map(int, input().split(' ')))
ans = -21828918921
for i in range(len(lst) - 1):
	ans = max(lst[i] - lst[i + 1] - p, ans)
if ans < 0:
	print(0)
else:
	print(ans)


(y, x) = list(map(int, input().split()))
nums = list(map(int, input().split()))
ans = 0
for i in range(1, len(nums)):
	ans = max(ans, nums[i - 1] - nums[i] - x)
print(ans)


import math

def ost(a, b):
	if a % b != 0:
		return 1
	return 0
(n, k) = map(int, input().split())
ans = 0
data = list(map(int, input().split()))
for i in range(n - 1):
	if data[i] - data[i + 1] - k > 0 and data[i] - data[i + 1] - k > ans:
		ans = data[i] - data[i + 1] - k
print(ans)


(n, c) = map(int, input().split())
l = list(map(int, input().split()))
mx = -100
for i in range(n - 1):
	x = l[i] - l[i + 1] - c
	mx = max(mx, x)
if mx > 0:
	print(mx)
else:
	print(0)


inpt = [int(item) for item in input().split()]
x = [int(item) for item in input().split()]
newlist = []
for item in range(inpt[0] - 1):
	if x[item] - x[item + 1] > 0:
		newlist.append((x[item] - x[item + 1], item))
	else:
		pass
newlist.sort(reverse=True)
if len(newlist) == 0:
	print(0)
elif x[newlist[0][1]] - inpt[1] - x[newlist[0][1] + 1] > 0:
	print(x[newlist[0][1]] - inpt[1] - x[newlist[0][1] + 1])
else:
	print(0)


(n, s) = map(int, input().split())
l = list(map(int, input().split()))
r = -1
for i in range(1, n):
	if l[i] < l[i - 1]:
		p = l[i - 1] - l[i] - s
		r = max(r, p)
if r > 0:
	print(r)
else:
	print(0)


s = input().rstrip().split(' ')
(n, c) = (int(s[0]), int(s[1]))
x = input().rstrip().split(' ')
max = int(x[0]) - int(x[1]) - c
for i in range(1, n - 1):
	if int(x[i]) - int(x[i + 1]) - c > max:
		max = int(x[i]) - int(x[i + 1]) - c
if max < 0:
	max = 0
print(max)


(n, c) = map(int, input().split())
a = list(map(int, input().split()))
maxi = 0
for i in range(n - 1):
	if a[i] - a[i + 1] - c > maxi:
		maxi = a[i] - a[i + 1] - c
else:
	print(maxi)


(n, c) = list(map(int, input().rstrip().split()))
x = list(map(int, input().rstrip().split()))
out = 0
for i in range(n - 1):
	if x[i] > x[i + 1]:
		prof = x[i] - x[i + 1] - c
		out = max(out, prof)
print(out)


(n, c) = map(int, input().split())
k = list(map(int, input().split()))
l = []
for i in range(n - 1):
	l.append(k[i] - k[i + 1] - c)
h = max(l)
if h > 0:
	print(h)
else:
	print('0')


(n, c) = map(int, input().split())
l = list(map(int, input().split()))
ma = c
for i in range(1, n):
	t = l[i - 1] - l[i]
	if ma < t:
		ma = t
print(ma - c)


(n, c) = map(int, input().split())
x = [int(n) for n in input().split()]
profit = 0
day = 0
for i in range(n - 1):
	p = x[i] - x[i + 1] - c
	if p > profit:
		profit = p
		day = i
print(profit)


(a, b) = map(int, input().split())
list1 = [int(h) for h in input().split()]
list2 = []
for i in range(0, a - 1):
	list2.append(list1[i] - list1[i + 1])
d = max(list2) - b
if d < 0:
	print(0)
else:
	print(d)


import logging
import copy
import sys
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

def solve(firstLine, inputLines):
	m = 0
	x = firstLine[1]
	for i in range(len(inputLines) - 1):
		s = inputLines[i] - inputLines[i + 1] - x
		if s > m:
			m = s
	return m

def main():
	firstLine = input().split()
	firstLine = list(map(int, firstLine))
	line = input().split()
	line = list(map(int, line))
	print(solve(firstLine, line))

def log(*message):
	logging.debug(message)
main()


def main():
	(n, c) = map(int, input().split())
	l = list(map(int, input().split()))
	print(max(0, max((a - b for (a, b) in zip(l, l[1:]))) - c))
main()


(n, c) = list(map(int, input().split()))
x = list(map(int, input().split()))
profit = 0
for i in range(n - 1):
	daily = x[i] - x[i + 1] - c
	if daily > profit:
		profit = daily
print(profit)


n = input().split()
x = input().split()
mx = 0
for i in range(0, len(x) - 1):
	jlh = int(x[i]) - int(x[1 + i]) - int(n[1])
	if jlh > mx:
		mx = jlh
print(mx)


def barrel_to_honey(n, c, a):
	biggest = 0
	for x in range(n - 1):
		if a[x] - (a[x + 1] + c) > biggest:
			biggest = a[x] - (a[x + 1] + c)
	return biggest
(n, c) = list(map(int, input().split()))
a = list(map(int, input().split()))
print(barrel_to_honey(n, c, a))


import sys
import math as m

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l
mod = int(1000000000.0) + 7

def sinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def ninp():
	return map(int, sys.stdin.readline().strip().split())

def linp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(a):
	print(a)

def p2(a, b):
	print(a, b)
(n, c) = ninp()
x = linp()
diff = -23423
for i in range(n - 1):
	diff = max(diff, x[i] - x[i + 1])
if diff - c <= 0:
	print(0)
else:
	print(diff - c)


(n, c) = map(int, input().split())
data = list(map(int, input().split()))
val = 0
for i in range(n - 1):
	val = max(val, data[i] - data[i + 1])
print(max(0, val - c))


(n, c) = [int(i) for i in input().split()]
kiloDays = [int(i) for i in input().split()]
maxKilos = 0
for i in range(0, n - 1):
	maxKilos = max(maxKilos, kiloDays[i] - kiloDays[i + 1] - c)
print(maxKilos)


import sys
inp = sys.stdin
(n, c) = map(int, inp.readline().split())
x = list(map(int, inp.readline().split()))
maxProfit = 0
i = 0
while i < len(x) - 1:
	profit = x[i] - x[i + 1] - c
	if profit > maxProfit:
		maxProfit = profit
	i += 1
print(maxProfit)


def beer(lst, k):
	result = 0
	for i in range(len(lst)):
		if i > 0:
			result = max(result, lst[i - 1] - lst[i] - k)
	return result
(n, c) = [int(i) for i in input().split()]
a = [int(j) for j in input().split()]
print(beer(a, c))


import sys
(n, c) = map(int, input().split())
a = list(map(int, input().split()))
maxi = 0
p = -1
r = -1
for i in range(0, n - 1):
	if maxi < a[i] - a[i + 1]:
		maxi = a[i] - a[i + 1]
		p = i + 1
if maxi - c <= 0:
	print(0)
else:
	print(maxi - c)


(N, c) = map(int, input().split())
A = list(map(int, input().split()))
cur = None
for i in range(1, len(A)):
	if cur == None:
		cur = A[i - 1] - A[i]
	else:
		cur = max(cur, A[i - 1] - A[i])
if cur == None or cur - c < 0:
	print(0)
else:
	print(cur - c)


MAX = 0
(n, c) = map(int, input().split())
kurs_kg = [int(i) for i in input().split()]
for i in range(1, n):
	if MAX < kurs_kg[i - 1] - kurs_kg[i] - c:
		MAX = kurs_kg[i - 1] - kurs_kg[i] - c
print(MAX)


(n, c) = map(int, input().split())
nl = list(map(int, input().split()))
M = 0
for i in range(n - 1):
	diff = nl[i] - nl[i + 1]
	if diff > 0:
		diff -= c
		if diff > M:
			M = diff
print(M)


from collections import Counter
(n, c) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
m = -1000
for i in range(n - 1):
	d = arr[i] - arr[i + 1]
	if d > m:
		m = d
profit = m - c
if profit > 0:
	print(profit)
else:
	print(0)


from sys import stdin, stdout
input = stdin.readline
(n, c) = map(int, input().split())
x = list(map(int, input().split()))
ma = x[0] - x[1]
for i in range(2, n):
	ma = max(x[i - 1] - x[i], ma)
stdout.write(str(max(0, ma - c)))


(n, c) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
p = []
for i in range(n - 1):
	z = a[i]
	o = a[i + 1]
	h = z - o
	p.append(h - c)
print(max(max(p), 0))


(n, c) = map(int, input().split())
k = list(map(int, input().split()))
max = 0
for i in range(len(k) - 1):
	if k[i] > c:
		if k[i] - c - k[i + 1] > 0:
			t = k[i] - c - k[i + 1]
			if t > max:
				max = t
print(max)


(n, c) = map(int, input().split())
x = list(map(int, input().split()))
sell_day = 0
buy_day = 0
max = float('-inf')
for i in range(n - 1):
	if max < x[i] - x[i + 1]:
		max = x[i] - x[i + 1]
		sell_day = i
		buy_day = i + 1
profit = x[sell_day] - x[buy_day] - c
if profit > 0:
	print(profit)
else:
	print(0)


res = 0
(n, m) = map(int, input().split())
t = list(map(int, input().split()))
for i in range(n - 1):
	if t[i] > t[i + 1] + m:
		res = max(res, t[i] - t[i + 1] - m)
print(res)


(n, c) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
	d = l[i] - l[i + 1] - c
	ans = max(ans, d)
print(ans)


[n, c] = input().split()
maxof = 0
c = int(c)
g = input().split()
for i in range(1, int(n)):
	h = int(g[i - 1])
	k = int(g[i])
	if maxof < h - k - c:
		maxof = h - k - c
print(maxof)


import sys
n_borrow = sys.stdin.readline().split()
n = int(n_borrow[0])
borrow = int(n_borrow[1])
lista = sys.stdin.readline().split()
for i in range(n):
	lista[i] = int(lista[i])
mayordif = 0
for i in range(n - 1):
	aux = lista[i] - lista[i + 1]
	if aux > mayordif:
		mayordif = aux
if mayordif == 0:
	print(0)
elif mayordif < borrow:
	print(0)
else:
	print(mayordif - borrow)


(x, y) = input().split()
(a, b) = (int(x), int(y))
list = []
list1 = []
list = [int(x) for x in input().split()]
for j in range(a):
	try:
		x = list[j] - list[j + 1] - b
	except:
		break
	if x > 0:
		list1.append(x)
list1.append(0)
print(max(list1))


a = [int(i) for i in input().split()]
n = a[0]
c = a[1]
m = -1000000000
x = [int(i) for i in input().split()]
for i in range(n - 1):
	if x[i] - x[i + 1] > m:
		m = x[i] - x[i + 1]
if m >= c:
	print(m - c)
else:
	print(0)


(n, d) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
	ele = l[i]
	for j in range(i + 1, i + 2):
		if j != i and j < n:
			ans = max(ans, ele - l[j] - d)
print(ans)


import sys, math, heapq, random, collections, bisect

def main():
	n = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	c_lst = lst[:]
	c_lst.sort()
	if c_lst == lst:
		print(0)
	else:
		c_lst.reverse()
		mx = 0
		rp = 0
		for i in c_lst:
			if rp == i:
				if lst[idx_ + 1:].index(i) < len(lst[idx_ + 1:]) - 1:
					idx = lst[idx_ + 1:].index(i)
					if lst[idx_ + 1:][idx] - lst[idx_ + 1:][idx + 1] > mx:
						mx = lst[idx_ + 1:][idx] - lst[idx_ + 1:][idx + 1]
				idx_ = idx + idx_ + 1
			elif lst.index(i) < len(lst) - 1:
				idx = lst.index(i)
				idx_ = idx
				rp = i
				if lst[idx] - lst[idx + 1] > mx:
					mx = lst[idx] - lst[idx + 1]
			elif i < mx:
				break
		if mx - n[1] > 0:
			print(mx - n[1])
		else:
			print(0)
main()


def read():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	return (n, x, a)

def solve(n, x, a):
	p = 0
	for i in range(n - 1):
		pi = a[i] - a[i + 1] - x
		p = max(p, pi)
	return p
result = solve(*read())
print(result)


(n, c) = map(int, input().split())
arr = list(map(int, input().split()))
print(max(0, max(map(lambda x: x[0] - x[1], zip([0] + arr[:-1], arr))) - c))


(n, c) = map(int, input().split())
x = list(map(int, input().split()))
counter = 0
for i in range(n - 1):
	if x[i] - x[i + 1] > counter:
		counter = x[i] - x[i + 1]
print(max(counter - c, 0))


(n, c) = map(int, input().split())
a = list(map(int, input().split()))
m = int(0)
for i in range(n - 1):
	x = a[i] - a[i + 1] - c
	m = max(m, x)
print(m)


(x, y) = map(int, input().split())
li = list(map(int, input().split()))
print(max(0, max([li[i] - li[i + 1] - y for i in range(x - 1)])))


(nod, extra) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
maxp = 0
for i in range(1, nod):
	maxp = max(maxp, arr[i - 1] - arr[i] - extra)
print(maxp)


(n, c) = [int(x) for x in input().split()]
numbers = [int(x) for x in input().split()]
profit = 0
for i in range(0, n - 1):
	if numbers[i] - numbers[i + 1] - c > profit:
		profit = numbers[i] - numbers[i + 1] - c
print(profit)


(n, c) = map(int, input().strip().split())
xs = list(map(int, input().strip().split()))
ans = 0
for (i, j) in zip(xs, xs[1:]):
	ans = max(ans, i - j - c)
print(ans)


line1 = [int(i) for i in str(input()).split(' ')]
prices = [int(i) for i in str(input()).split(' ')]
rent = []
for i in range(1, len(prices)):
	rent.append(prices[i - 1] - prices[i] - line1[1])
if max(rent) > 0:
	print(max(rent))
else:
	print(0)


(n, c) = map(int, input().split())
X = list(map(int, input().split()))
print(max(0, max((X[i] - X[i + 1] for i in range(n - 1))) - c))


(n, t) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
diff = -1
for i in range(n - 1):
	if a[i] - a[i + 1] > diff:
		diff = a[i] - a[i + 1]
if diff > 0 and diff > t:
	print(diff - t)
else:
	print(0)


l = input().split(' ')
n = int(l[0])
c = int(l[1])
str_arr = input().split()
arr = [int(num) for num in str_arr]
max_diff = arr[0] - arr[1]
idx = 0
for i in range(1, len(arr) - 1):
	diff = arr[i] - arr[i + 1]
	if diff > 0 and diff > max_diff:
		max_diff = diff
		idx = i
ans = arr[idx] - arr[idx + 1] - c
if max_diff < 0 or ans < 0:
	print('0')
else:
	print(ans)


(n, k) = map(int, input().split())
max = 0
tmp = 0
x = list(map(int, input().split()))
for i in range(n - 1):
	if x[i] > x[i + 1] + k:
		tmp = x[i] - (x[i + 1] + k)
	if tmp > max:
		max = tmp
print(max)


(n, c) = list(map(int, input().split()))
data = list(map(int, input().split()))
profit = [0]
for i in range(len(data) - 1):
	if data[i] > data[i + 1]:
		profit.append(data[i] - data[i + 1] - c)
print(max(profit))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
k = 0
for i in range(n - 1):
	if l[i] > l[i + 1] + m:
		if k < l[i] - l[i + 1] - m:
			k = l[i] - l[i + 1] - m
print(k)


(n, c) = list(map(int, input().rstrip().split()))
x = list(map(int, input().rstrip().split()))
g = 0
for i in range(n - 1):
	if x[i] - x[i + 1] > g:
		g = x[i] - x[i + 1]
if g - c >= 0:
	print(g - c)
else:
	print(0)


(n, c) = map(int, input().split())
(last, best) = (-1, 0)
for x in map(int, input().split()):
	t = last - x - c
	best = max(best, t)
	last = x
print(best)


(n, c) = map(int, input().strip().split(' '))
arr = list(map(int, input().strip().split(' ')))
list1 = []
for i in range(n - 1):
	a = arr[i] - arr[i + 1] - c
	list1.append(a)
if max(list1) > 0:
	print(max(list1))
else:
	print('0')


(days, kilos) = map(int, input().split())
prices = list(map(int, input().split()))
profit = 0
for i in range(days - 1):
	profit = max(profit, prices[i] - prices[i + 1] - kilos)
print(profit)


p = [int(n) for n in input().split()]
s = [int(n) for n in input().split()]
op = []
pq = []
for n in range(len(s) - 1):
	pq.append(s[n] - s[n + 1])
if max(pq) - p[1] < 0:
	print(0)
else:
	print(max(pq) - p[1])


(n, c) = list(map(int, input().split()))
x = list(map(int, input().split()))
sub = 0
for i in range(len(x) - 1):
	a = x[i] - x[i + 1]
	if sub < a:
		sub = a
if sub - c < 0:
	print(0)
else:
	print(sub - c)


(n, c) = map(int, input().split())
arr = [int(x) for x in input().split()]
mx = 0
for i in range(n - 1):
	val = arr[i] - arr[i + 1] - c
	if val > 0:
		mx = max(mx, val)
print(mx)


(a, b) = [int(i) for i in input().split()]
m = 0
s = [int(i) for i in input().split()]
for i in range(len(s) - 1):
	m = max(m, s[i] - s[i + 1] - b)
print(m)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
s = 0
for i in range(1, n):
	s = max(s, a[i - 1] - a[i])
if s <= 0 or s - x <= 0:
	print(0)
else:
	print(s - x)


(a, b) = map(int, input().split(' '))
l = []
p = []
l = list(map(int, input().split(' ')))
for i in range(0, a - 1):
	m = l[i] - l[i + 1]
	p.append(m)
n = max(p)
n = n - b
if n > 0:
	print(n)
else:
	print(0)


(n, c) = map(int, input().split())
l = list(map(int, input().split()))
m = 100000
temp = []
for i in range(n - 1):
	temp.append(l[i] - l[i + 1])
m = max(temp)
if m <= 0 or m < c:
	print(0)
else:
	idx = temp.index(m)
	profit = l[idx] - l[idx + 1] - c
	print(profit)


data = input().split()
(N, C) = (int(data[0]), int(data[1]))
barels_prices = input().split()
barels_prices = list(map(int, barels_prices))
max_price = []
for i in range(N - 1):
	max_price.append(barels_prices[i] - barels_prices[i + 1] - C)
if max(max_price) == abs(max(max_price)):
	print(max(max_price))
else:
	print('0')


(n, c) = map(int, input().split())
prices = list(map(int, input().split()))
returns = []
returns = [prices[i] - prices[i + 1] - c for i in range(n - 1)]
if max(returns) > 0:
	print(max(returns))
else:
	print(0)


(n, c) = map(int, input().split(' '))
x = list(map(int, input().split(' ')))
ans = 0
for i in range(0, n - 1):
	if x[i] - x[i + 1] - c > ans:
		ans = x[i] - x[i + 1] - c
print(ans)


(n, c) = map(int, input().split())
a = list(map(int, input().split()))
mx = a[0] - a[1]
for i in range(2, n):
	mx = max(mx, a[i - 1] - a[i])
print(max(0, mx - c))


from sys import stdin, stdout
nc = list(map(int, stdin.readline().strip().split()))
n = nc[0]
c = nc[1]
prices = list(map(int, stdin.readline().split()))
max_rasp = prices[0] - (prices[1] + c)
for i in range(1, n - 1):
	max_rasp = max(max_rasp, prices[i] - (prices[i + 1] + c))
if max_rasp < 0:
	stdout.write('0')
else:
	stdout.write(str(max_rasp))


from __future__ import division, print_function
from collections import *
from math import *
from itertools import *
from time import time
import os
import string
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	(n, c) = map(int, input().split())
	li = list(map(int, input().split()))
	amount = 0
	for i in range(n - 1):
		res = li[i] - li[i + 1] - c
		if res >= amount:
			amount = res
		else:
			continue
	print(amount)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def maxdiff(lst):
	max = 0
	i = 0
	index = 'empty'
	while i < len(lst) - 1:
		if lst[i] - lst[i + 1] > max:
			max = lst[i] - lst[i + 1]
			index = i
			i += 1
		else:
			i += 1
	return index
(n, m) = [int(x) for x in input().split()]
lst = [int(x) for x in input().split()]
if maxdiff(lst) == 'empty':
	print(0)
else:
	sum = lst[maxdiff(lst)] - lst[maxdiff(lst) + 1] - m
	if sum < 0:
		print(0)
	else:
		print(sum)


(n, c) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
ans = 0
for (a, b) in zip(l[:-1], l[1:]):
	ans = max(ans, a - b - c)
print(ans)


(n, c) = map(int, input().split())
pr = list(map(int, input().split()))
maxim = 0
for cont in range(0, n - 1, 1):
	m = pr[cont] - pr[cont + 1] - c
	if m > maxim:
		maxim = m
print(maxim)


(n, c) = map(int, input().split())
a = list(map(int, input().split()))
r = []
for j in range(len(a) - 1):
	r.append(a[j] - a[j + 1])
y = r.index(max(r))
x1 = a[y]
x2 = a[y + 1]
m = x1 - x2 - c
if m <= 0:
	print(0)
else:
	print(m)


(n, c) = map(int, input().split())
a = list(map(int, input().split()))
s = 0
for i in range(n - 1):
	if a[i] > a[i + 1]:
		s = max(s, a[i] - a[i + 1] - c)
print(s)


(n, y) = [int(x) for x in input().split()]
li = [int(x) for x in input().split()]
maxDiff = 0
for x in range(n - 1):
	if maxDiff < li[x] - li[x + 1]:
		maxDiff = li[x] - li[x + 1]
if maxDiff - y > 0:
	print(maxDiff - y)
else:
	print(0)


def main():
	(n, c) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	ma = 0
	for i in range(n - 1):
		ma = max(a[i] - a[i + 1] - c, ma)
	return ma
print(main())


(n, c) = map(int, input().split(' '))
X = [int(x) for x in input().split(' ')]
A = []
for i in range(n - 1):
	A.append(X[i] - X[i + 1])
for j in range(n - 1):
	if A[j] == max(A):
		break
if max(A) > 0:
	if X[j] - X[j + 1] - c > 0:
		print(X[j] - X[j + 1] - c)
	else:
		print(0)
else:
	print(0)


(n, d) = input().split()
n = int(n)
d = int(d)
h = list(map(int, input().split()))
m = 0
for i in range(1, n):
	m = max(m, h[i - 1] - h[i] - d)
print(m)


from math import *
(n, c) = map(int, input().split())
r = [int(i) for i in input().split()]
maxx = -1000000000.0
for i in range(n - 1):
	maxx = max(maxx, r[i] - r[i + 1])
if maxx >= c:
	print(maxx - c)
else:
	print(0)


(n, c) = map(int, input().split())
a = list(map(int, input().split()))
root = 0
index = -1
for i in range(0, n - 1):
	v = a[i] - a[i + 1] - c
	if v > root:
		root = v
		index = i
print(root)


s = input()
l = s.split(' ')
c = int(l[1])
n = int(l[0])
s = input()
l = s.split(' ')
b = []
for i in l:
	b.append(int(i))
m = 0
for i in range(len(b) - 1):
	if b[i] - b[i + 1] - c > m:
		m = b[i] - b[i + 1] - c
print(m)


def raspberry():
	total = list(map(int, input().split()))
	prices = list(map(int, input().split()))
	output = 0
	for i in range(len(prices)):
		if i == len(prices) - 1:
			break
		bought = prices[i + 1]
		sold = prices[i]
		temp = sold - bought - total[1]
		if temp > output:
			output = temp
	return output
A = raspberry()
print(A)


from sys import stdin, stdout
(n, c) = map(int, stdin.readline().split())
ar = list(map(int, stdin.readline().split()))
ans = 0
for i in range(n - 1):
	if ar[i] - ar[i + 1] - c >= ans:
		ans = ar[i] - ar[i + 1] - c
stdout.write(str(ans) + '\n')


firstLine = [int(x) for x in input().split()]
secondLine = [int(x) for x in input().split()]
best = 0
for i in range(0, len(secondLine) - 1):
	temp = secondLine[i] - secondLine[i + 1] - firstLine[1]
	if temp > best:
		best = temp
print(best)


import os
import sys
from io import BytesIO, IOBase
import math as M
import itertools as ITR
from collections import defaultdict as D
from collections import Counter as C
from collections import deque as Q
import threading
from functools import lru_cache, reduce
from functools import cmp_to_key as CMP
from bisect import bisect_left as BL
from bisect import bisect_right as BR
import random as R
import string
import cmath, time
enum = enumerate
start_time = time.time()
MOD = 1000000007
MA = float('inf')
MI = float('-inf')
di8 = ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1))
di4 = ((1, 0), (0, 1), (-1, 0), (0, -1))

def increase_stack():
	sys.setrecursionlimit(2 ** 32 // 2 - 1)
	threading.stack_size(1 << 27)

def binary(n):
	return bin(n)[2:]

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def maxfactor(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
	if q:
		return q[-1]

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(M.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	l.sort()
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def seive(n):
	a = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	prime[0] = prime[1] = False
	return (a, prime)

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(M.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countchar(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def str_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def lis(arr):
	n = len(arr)
	lis = [1] * n
	maximum = 0
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
				maximum = max(maximum, lis[i])
	return maximum

def lcm(arr):
	a = arr[0]
	val = arr[0]
	for i in range(1, len(arr)):
		gcd = gcd(a, arr[i])
		a = arr[i]
		val *= arr[i]
	return val // gcd

def ncr(n, r):
	return M.factorial(n) // (M.factorial(n - r) * M.factorial(r))

def npr(n, r):
	return M.factorial(n) // M.factorial(n - r)

def IF(c, t, f):
	return t if c else f

def YES(c):
	print(IF(c, 'YES', 'NO'))

def Yes(c):
	print(IF(c, 'Yes', 'No'))

def yes(c):
	print(IF(c, 'yes', 'no'))

def JA(a, sep=' '):
	print(sep.join(map(str, a)))

def JAA(a, s='\n', t=' '):
	return s.join((t.join(map(str, b)) for b in a))

def PS(a, s=' '):
	print(str(a), end=s)

def I():
	return int(inp())

def F():
	return float(inp())

def LI():
	return list(map(int, inp().split()))

def LF():
	return list(map(float, inp().split()))

def MATI(n):
	return [LI() for i in range(n)]

def MATS(n):
	return [list(inp()) for i in range(n)]

def IV():
	return map(int, inp().split())

def FV():
	return map(float, inp().split())

def LS():
	return list(inp())

def S():
	return inp()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
inp = lambda : sys.stdin.readline().rstrip('\r\n')
TestCases = 0

def solve():
	(n, r) = IV()
	arr = LI()
	ma = 0
	for i in range(1, n):
		ma = max(ma, arr[i - 1] - arr[i])
	print(ma - r) if ma - r > 0 else print(0)

def main():
	flag = 1
	try:
		sys.stdin = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/input.txt', 'r')
		sys.stdout = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/output.txt', 'w')
	except:
		flag = 0
	t = 1
	if TestCases:
		t = I()
	for _ in range(1, t + 1):
		solve()
	if flag:
		print('Time: %.4f sec' % (time.time() - start_time))
		localtime = time.asctime(time.localtime(time.time()))
		print(localtime)
		sys.stdout.close()
main()


(n, c) = map(int, input().split())
xs = list(map(int, input().split()))
maxi = 0
for i in range(n - 1):
	maxi = max(maxi, xs[i] - xs[i + 1] - c)
print(maxi)


import sys
from math import *
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
ls = lambda : list(input().strip())
from collections import defaultdict as df
import heapq
infinite = float('inf')
(n, c) = RI()
l = RI()
maxo = 0
for i in range(n - 1):
	temp = l[i] - c - l[i + 1]
	maxo = max(temp, maxo)
print(maxo)


(n, k) = map(int, input().split())
t = list(map(int, input().split()))
p = max([t[i - 1] - t[i] for i in range(1, n)])
print(0 if p < k else p - k)


import sys

def data():
	return sys.stdin.readline().strip()

def sp():
	return map(int, data().split())

def l():
	return list(sp())
temp = l()
n = temp[0]
c = temp[1]
prices = l()
ans = 0
for i in range(n - 1):
	if i + 1 > n:
		continue
	ans = max(ans, prices[i] - prices[i + 1] - c)
	if ans < 0:
		ans = 0
if prices[0] != min(prices):
	print(ans)
else:
	print(0)


def main():
	(n, c) = map(int, input().split())
	x = list(map(int, input().split()))
	d = [0]
	for i in range(len(x) - 1):
		if x[i] > x[i + 1]:
			d.append(x[i] - x[i + 1] - c)
	d.sort()
	print(d[-1])
main()


(d, r) = list(map(int, input().split()))
l = list(map(int, input().split()))
MD = 1e-10
index = -1
for i in range(d - 1):
	diff = l[i] - l[i + 1]
	if diff > MD:
		MD = diff
		index = i
if MD < 1 or MD - r < 0:
	print(0)
else:
	print(MD - r)


(n, c) = [int(x) for x in input().split()]
days = [int(x) for x in input().split()]
max_diff = 0
for i in range(1, n):
	if days[i - 1] - days[i] > max_diff:
		max_diff = days[i - 1] - days[i]
if max_diff - c <= 0:
	print(0)
else:
	print(max_diff - c)


yo = list(map(int, input().split()))
n = yo[0]
c = yo[1]
x = list(map(int, input().split()))
maxdip = 0
flag = 0
for i in range(1, n):
	if x[i - 1] - x[i] >= maxdip:
		flag = 1
		maxdip = x[i - 1] - x[i]
ans = maxdip - c
if flag == 0 or ans < 0:
	print(0)
else:
	print(ans)


(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
max1 = 0
for i in range(len(l1) - 1):
	m1 = l1[i] - l1[i + 1]
	if max1 < m1:
		max1 = m1
if max1 >= k:
	print(max1 - k)
else:
	print(0)


(d, m) = (int(i) for i in input().split())
ex = [int(i) for i in input().split()]
mx = 0
for i in range(d - 1):
	mx = max(mx, ex[i] - ex[i + 1])
print((mx - m) * (mx > m))


(n, c) = map(int, input().split())
m = list(map(int, input().split()))
li = []
for i in range(1, n):
	li.append(m[i - 1] - (m[i] + c))
if max(li) > 0:
	ans = max(li)
else:
	ans = 0
print(ans)


(n, c) = map(int, input().split())
x = list(map(int, input().split()))
tmpMax = 0
indMax = 0
for i in range(n - 1):
	Dif = x[i] - x[i + 1]
	if Dif > tmpMax:
		tmpMax = Dif
		indMax = i
profit = x[indMax] - x[indMax + 1] - c
if profit >= 0:
	print(profit)
else:
	print(0)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
a = 0
for i in range(1, n):
	if l[i] - l[i - 1] < 0:
		x = l[i - 1] - l[i] - m
		if x > a:
			a = x
print(a)


(n, c) = map(int, input().split())
barrel = list(map(int, input().split()))
i = 0
profit = 0
while i < len(barrel) - 1:
	if barrel[i] - barrel[i + 1] - c > profit:
		profit = barrel[i] - barrel[i + 1] - c
	i = i + 1
print(profit)


s = input()
a = s.split(' ')
n = int(a[0])
c = int(a[1])
s = input()
a = s.split(' ')
mx = 0
for i in range(n):
	a[i] = int(a[i])
for i in range(0, n - 1):
	if a[i] - a[i + 1] - c > mx:
		mx = a[i] - a[i + 1] - c
print(mx)


st = input().split()
n = int(st[0])
c = int(st[1])
x = input().split()
ans = 0
for i in range(n - 1):
	ans = max(ans, int(x[i]) - int(x[i + 1]) - c)
print(ans)


a = int(input().split()[1])
b = list(map(int, input().split()))
b = [b[0]] + b
c = max(map(lambda x: b[x] - b[x + 1], range(len(b) - 1)))
print(max(c - a, 0))


R = lambda : map(int, input().split())
(n, r) = R()
p = ans = 0
for i in R():
	ans = max(ans, p - i - r)
	p = i
print(ans)


(n, c) = list(map(lambda x: int(x), input().split()))
lstx = list(map(lambda x: int(x), input().split()))
profit = 0
for nitem in range(len(lstx) - 1):
	if lstx[nitem] - lstx[nitem + 1] - c > profit:
		profit = lstx[nitem] - lstx[nitem + 1] - c
print(profit)


string = input()
numbers = string.split(' ')
a = int(numbers[0])
b = int(numbers[1])
string = input()
numbers = string.split(' ')
for x in range(a):
	numbers[x] = int(numbers[x])
raspberries = []
for x in range(a - 1):
	y = numbers[x]
	z = numbers[x + 1]
	value = y - z - b
	if value >= 0:
		raspberries.append(value)
if len(raspberries) == 0:
	maximum = 0
else:
	maximum = max(raspberries)
print(maximum)


line = input()
line = line.split()
n = int(line[0])
c = int(line[1])
line = input()
line = line.split()
xtra = 0
line[0] = int(line[0])
for i in range(1, n):
	line[i] = int(line[i])
	if line[i - 1] - line[i] - c > xtra:
		xtra = line[i - 1] - line[i] - c
print(xtra)


(n, c) = map(int, input().split())
x = input().split()
res = c
for i in range(n - 1):
	res = max(res, int(x[i]) - int(x[i + 1]))
print(max(0, res - c))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
	if l[i] - l[i + 1] > ans:
		ans = l[i] - l[i + 1]
if ans - m > 0:
	print(ans - m)
else:
	print(0)


(n, c) = map(int, input().split())
arr = list(map(int, input().split()))
ans = float('-inf')
for i in range(1, n):
	ans = max(ans, arr[i - 1] - arr[i])
if ans - c < 0:
	print(0)
else:
	print(ans - c)


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
maxi = 0
for i in range(n - 1):
	if s[i] - s[i + 1] > maxi:
		maxi = s[i] - s[i + 1]
print(max(0, maxi - m))


I = lambda : list(map(int, input().split()))
(n, c) = I()
a = I()
print(max([a[i] - a[i + 1] - c for i in range(n - 1)] + [0]))


(n, c) = map(int, input().split())
a = input().split()
res = c
for i in range(n - 1):
	res = max(res, int(a[i]) - int(a[i + 1]))
ass = max(0, res - c)
print(ass)


(n, c) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
k = max((A[i] - A[i + 1] for i in range(n - 1)))
print(max(0, k - c))


(a, b) = map(int, input().split())
lista = list(map(int, input().split()))
soma = 0
for c in range(a - 1):
	if lista[c] - lista[c + 1] - b > soma:
		soma = lista[c] - lista[c + 1] - b
print(soma)


data = [int(x) for x in input().split()]
days = [int(x) for x in input().split()]
profit = 0
answer = []
for i in range(data[0] - 1):
	profit = days[i] - days[i + 1]
	answer.append(profit)
	profit = 0
if max(answer) - data[1] <= 0:
	print(0)
else:
	print(max(answer) - data[1])


(n_val, c_val) = list(map(int, input().split()))
trade = list(map(int, input().split()))
profit = list()
for day in range(1, n_val):
	profit.append(trade[day] - trade[day - 1])
profit_max = min(profit)
if profit_max >= -c_val:
	profit_max = 0
else:
	profit_max = abs(profit_max) - c_val
print(profit_max)


from sys import stdin
(n, c) = map(int, stdin.readline().split())
arr = list(map(int, stdin.readline().split()))
max_m = 0
for i in range(1, n):
	val = arr[i - 1] - arr[i] - c
	max_m = max(max_m, val)
print(max_m)


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
lst = []
for i in range(n - 1):
	lst.append(a[i] - a[i + 1])
ans = max(max(lst) - m, 0)
print(ans)


dia_preco = list(map(int, input().split()))
cot_dia = list(map(int, input().split()))
mlhr_neg = 0
dia_atual = 0
for cot in range(len(cot_dia)):
	if cot + 1 >= len(cot_dia):
		break
	else:
		dia_atual = cot_dia[cot] - cot_dia[cot + 1]
		if dia_atual > mlhr_neg:
			mlhr_neg = dia_atual
print(mlhr_neg - dia_preco[1] if mlhr_neg - dia_preco[1] >= 0 else 0)


(n, c) = map(int, input().split())
a = list(map(int, input().split()))
profit = 0
for i in range(1, len(a)):
	if a[i - 1] - a[i] - c <= 0:
		continue
	elif a[i - 1] - a[i] - c > profit:
		profit = a[i - 1] - a[i] - c
	else:
		continue
print(profit)


(n, c) = map(int, input().split())
l = list(map(int, input().rstrip().rsplit()))
lt = []
for i in range(n - 1):
	x = l[i] - l[i + 1] - c
	lt.append(x)
if max(lt) < 0:
	print(0)
else:
	print(max(lt))


(n, c) = input().split()
n = int(n)
c = int(c)
a = list(map(int, input().split()))
max_temp = 0
for i in range(n - 1):
	if a[i] > a[i + 1]:
		diff = a[i] - a[i + 1] - c
		if diff > max_temp:
			max_temp = diff
print(max_temp)


(n, c) = map(int, input().split())
list1 = list(map(int, input().split()))
dd = 0
e1 = 0
e2 = 0
for i in range(n - 1):
	d = list1[i] - list1[i + 1]
	if d > dd:
		dd = d
		e1 = list1[i]
		e2 = list1[i + 1]
if dd > 0:
	print(max(e1 - e2 - c, 0))
else:
	print(0)


(n, c) = map(int, input().split())
p = list(map(int, input().split()))
ls = []
for i in range(n - 1):
	ls.append(p[i] - p[i + 1] - c)
ls.append(0)
print(max(ls))


class plan(object):

	def __init__(self, n, c, a):
		self.n = n
		self.a = a
		self.c = c

	def sloved(self):
		x = 0
		for i in range(n - 1):
			if self.a[i] - self.a[i + 1] - self.c > x:
				x = self.a[i] - self.a[i + 1] - self.c
		return x
(n, c) = map(int, input().split())
a = [int(i) for i in input().split()]
print(plan(n, c, a).sloved())


x = input()
(days, cost) = [int(i) for i in x.split()]
prices = input()
prices = [int(i) for i in prices.split()]
largest = 0
for i in range(0, days - 1):
	diff = prices[i] - prices[i + 1] - cost
	if diff > largest:
		largest = diff
		indexLargest = i
if largest > 0:
	print(largest)
else:
	print('0')


(n, c) = map(int, input().split())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
m = 0
for i in range(n - 1):
	if a[i] - a[i + 1] - c > m:
		m = a[i] - a[i + 1] - c
print(m)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(n, c) = LI()
	a = LI()
	r = 0
	for i in range(n - 1):
		t = a[i] - a[i + 1] - c
		if r < t:
			r = t
	return r
print(main())


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
mx = 0
for i in range(n - 1):
	mx = max(mx, a[i] - a[i + 1] - m)
print(mx)


import sys
import math
(n, c) = [int(x) for x in sys.stdin.readline().split()]
x = [int(x) for x in sys.stdin.readline().split()]
max = 0
for i in range(n - 1):
	if x[i] - x[i + 1] > max:
		max = x[i] - x[i + 1]
if max - c < 0:
	print(0)
else:
	print(max - c)


(n, c) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
d = []
for i in range(n - 1):
	for j in range(i + 1, i + 2):
		d.append(a[i] - a[j])
if max(d) - c > 0:
	print(max(d) - c)
else:
	print('0')


(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
mini = l[n - 1]
prft = 0
for i in range(n - 2, -1, -1):
	curr = l[i] - l[i + 1] - k
	prft = max(prft, curr)
print(prft)


(n, c) = map(int, input().split())
a = list(map(int, input().split()))
m = 0
for i in range(len(a) - 1):
	p = a[i] - a[i + 1]
	m = max(m, p)
ans = m - c
if ans < 0:
	print('0')
else:
	print(ans)


(n, c) = map(int, input().split())
lis = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
	temp = lis[i] - lis[i + 1] - c
	ans = max(temp, ans)
print(ans)


(n, c) = map(int, input().split())
l = list(map(int, input().split()))
maxdif = 0
d = -1
for i in range(len(l) - 1):
	if l[i] - l[i + 1] > maxdif:
		maxdif = l[i] - l[i + 1]
		d = i
if d == -1:
	print(0)
else:
	t = l[d] - l[d + 1] - c
	if t > 0:
		print(t)
	else:
		print(0)


(n, c) = map(int, input().split())
a = list(map(int, input().split()))
d = 0
for i in range(n - 1):
	if a[i] - a[i + 1] - c > d:
		d = a[i] - a[i + 1] - c
print(d)


(n, c) = map(int, input().split())
arr = list(map(int, input().split()))
max = 0
if n < 3:
	if arr[0] - arr[1] - c <= 0:
		print(0)
	else:
		print(arr[0] - arr[1] - c)
else:
	for i in range(n - 1):
		if arr[i] > arr[i + 1]:
			j = i
			while j < n - 1:
				cnt = arr[j] - arr[j + 1]
				if cnt > max:
					max = cnt
				j += 1
	if max - c >= 0:
		print(max - c)
	else:
		print(0)


(n, c) = [int(s) for s in input().split(' ')]
x = [int(s) for s in input().split(' ')]
d = [x[i] - x[i + 1] for i in range(n - 1)]
ans = max(d) - c
print(max(ans, 0))


(n, c) = map(int, input().split(' '))
x = list(map(int, input().split(' ')))
curr = []
for i in range(1, len(x)):
	if x[i - 1] - x[i] == abs(x[i - 1] - x[i]):
		curr.append(x[i - 1] - x[i])
	else:
		curr.append(0)
if max(curr) > 0:
	if max(curr) - c > 0:
		print(max(curr) - c)
	else:
		print(0)
else:
	print(0)


import sys
(n, c) = map(int, sys.stdin.readline().split())
xn = list(map(int, sys.stdin.readline().split()))
ans = 0
for i in range(1, n):
	if xn[i - 1] - xn[i] > ans:
		ans = xn[i - 1] - xn[i]
ans = ans - c
if ans < 0:
	ans = 0
print(ans)


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, c) = get_ints()
Arr = get_array()
maxi = -1
for i in range(n - 1):
	if Arr[i] - Arr[i + 1] > maxi:
		maxi = Arr[i] - Arr[i + 1]
if maxi <= c:
	print(0)
else:
	print(maxi - c)


(a, b) = map(int, input().split(' '))
honey = list(map(int, input().split(' ')))
dhoney = [honey[x - 1] - honey[x] for x in range(1, len(honey))]
print(max(max(dhoney) - b, 0))


def solve(c, l):
	res = 0
	l = list(l)
	for i in range(len(l) - 1):
		res = max(res, l[i] - l[i + 1] - c)
	return res
(n, c) = map(int, input().split())
l = map(int, input().split())
print(solve(c, l))


(n, c) = map(int, input().split())
l = list(map(int, input().split()))
d = []
maxi = 0
ip = -1
pf = 0
for i in range(1, n):
	if l[i - 1] - l[i] > maxi:
		maxi = l[i - 1] - l[i]
		ip = i - 1
if ip > -1:
	pf = l[ip] - l[ip + 1]
	pf -= c
if pf > 0:
	print(pf)
else:
	print('0')


(n, c) = map(int, input().split())
l = list(map(int, input().split()))
diff = []
for i in range(0, n):
	if i < n - 1:
		diff.append(l[i] - l[i + 1])
ind = diff.index(max(diff))
ans = l[ind] - l[ind + 1] - c
if ans > 0:
	print(ans)
else:
	print(0)


(n, c) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [0] * (n - 1)
for i in range(n - 1):
	b[i] = a[i] - a[i + 1]
ans = max(b) - c
print(max(0, ans))


(x, y) = [int(x) for x in input('').split()]
ar = list(map(int, input('').split()))
diff = []
for i in range(len(ar) - 1):
	di = ar[i] - ar[i + 1]
	diff.append(di)
d = diff.index(max(diff))
j = ar[d] - ar[d + 1] - y
if j > 0:
	print(j)
else:
	print(0)