Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs a_{i} rubles. Only one person can hang clothes on one hook.

Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. 

Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight.


-----Input-----

The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 100). The third line contains integer m (1 ≤ m ≤ 100).


-----Output-----

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


-----Examples-----
Input
2 1
2 1
2

Output
3

Input
2 1
2 1
10

Output
-5



-----Note-----

In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles.

In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 =  - 5.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
s = [int(n) for n in input().split()]
z = [int(n) for n in input().split()]
m = int(input())
z.sort()
if m <= s[0]:
	k = sum(z[:m])
else:
	k = ((m - s[0]) * s[1] - sum(z)) * -1
print(k)


def main():
	l = input().split(' ')
	(n, d) = (int(l[0]), int(l[1]))
	k = input().split(' ')
	for x in range(0, n):
		k[x] = int(k[x])
	k.sort()
	m = int(input())
	sume = 0
	if n >= m:
		for x in range(0, m):
			sume = sume + k[x]
	else:
		for x in range(0, n):
			sume = sume + k[x]
		sume = sume - (m - n) * d
	print(sume)

def __starting_point():
	main()
__starting_point()


(n, d) = list(map(int, input().split()))
a = sorted(map(int, input().split()))
m = int(input())
if m < n:
	print(sum(a[:m]))
elif m == n:
	print(sum(a))
else:
	print(sum(a) - (m - n) * d)


(n, d) = map(int, input().split())
a = sorted(list(map(int, input().split())))
m = int(input())
print(sum(a[:min(n, m)]) - d * max(0, m - n))


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().split()))
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(n, d) = int_array()
a = sorted(int_array())
m = int(input())
ans = sum(a[:m])
if m > n:
	ans -= (m - n) * d
print(ans)


__author__ = 'sm'

def readln():
	return list(map(int, input().split()))
(n, d) = readln()
data = readln()
m = readln()[0]
data.sort()
cost = 0
j = 0
for i in range(m):
	if i >= len(data):
		cost -= d
	else:
		cost += data[i]
print(cost)


(n, d) = tuple(map(int, input().split(None, 2)))
a = list(map(int, input().split()))
assert len(a) == n
m = int(input())
a.sort()
if n <= m:
	print(sum(a) - d * (m - n))
else:
	print(sum(a[:m]))


def main():
	(n, d) = map(int, input().split())
	l = sorted(map(int, input().split()))
	m = int(input())
	print(sum(l[:m]) if m < n else sum(l) - (m - n) * d)
main()


import bisect
from itertools import accumulate
import os
import sys
import math
from io import BytesIO, IOBase
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')
(n, d) = map(int, input().split())
a = sorted(list(map(int, input().split())))
m = int(input())
i = 0
ans = 0
while m > 0:
	if i >= len(a):
		break
	else:
		ans += a[i]
		i += 1
		m -= 1
if m > 0:
	ans -= m * d
print(ans)


(n, d) = map(int, input().split())
lis = sorted(map(int, input().split()))
m = int(input())
ans = sum(lis[:min(n, m)]) - d * max(0, m - n)
print(ans)


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

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

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def rev(n):
	m = 0
	while n > 0:
		m = m * 10 + n % 10
		n = n // 10
	return m
(n, d) = mi()
a = li()
m = ii()
if m > n:
	print(sum(a) - (m - n) * d)
else:
	a.sort()
	print(sum(a[:m]))


from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations
from math import gcd, floor, inf
from bisect import bisect_right, bisect_left
(n, d) = map(int, input().split())
arr = sorted(map(int, input().split()))
m = int(input())
if m < n:
	print(sum(arr[:m]))
else:
	print(sum(arr) - d * (m - n))


M = lambda : map(int, input().split())
L = lambda : list(map(int, input().split()))
I = lambda : int(input())
(n, d) = M()
(a, k) = (sorted(L()), I())
print(sum(a) + (n - k) * d if n < k else sum(a[:k]))


(n, d) = map(int, input().split())
a = list(map(int, input().split()))
m = int(input())
if m > n:
	print(sum(a) - (m - n) * d)
else:
	a.sort()
	print(sum(a[0:m]))


(n, d) = map(int, input().split())
a = list(map(int, input().split()))
m = int(input())
if m > n:
	print(sum(a) - (m - n) * d)
else:
	a.sort()
	s = 0
	for i in range(m):
		s += a[i]
	print(s)


array = input('').split(' ')
totalsum = 0
summ = 0
n = array[0]
d = array[1]
listfromsmallesttolargest = input('').split(' ')
m = int(input(''))
for u in range(0, len(listfromsmallesttolargest)):
	summ = summ + int(listfromsmallesttolargest[u])
listfromsmallesttolargest = [int(x) for x in listfromsmallesttolargest]
listfromsmallesttolargest.sort()
if int(m) >= int(n):
	print(summ - int(d) * (int(m) - int(n)))
if int(m) < int(n):
	for bub in range(0, int(m)):
		totalsum = totalsum + int(listfromsmallesttolargest[bub])
	print(totalsum)


(n, d) = map(int, input().split())
l = list(map(int, input().split()))
m = int(input())
l.sort()
if m >= n:
	print(sum(l[:n]) - (m - n) * d)
else:
	print(sum(l[:m]))


from sys import stdin
(n, d) = map(int, stdin.readline().split())
a = sorted(map(int, stdin.readline().split()))
m = int(stdin.readline())
print(sum(a[:m]) - ((m - n) * d if m > n else 0))


import fileinput

def solve():
	with fileinput.input() as stdin:
		(n, d) = [int(c) for c in stdin.readline().split(' ')]
		a = [int(c) for c in stdin.readline().split(' ')]
		m = int(stdin.readline())
		a = sorted(a)
		res = 0
		if m > n:
			res = sum(a)
			res -= (m - n) * d
		else:
			for i in range(m):
				res += a[i]
		print(res)

def __starting_point():
	solve()
__starting_point()


(n, d) = map(int, input().split())
a = list(map(int, input().split()))
m = int(input())
s = 0
a = sorted(a)
zanyat = n - m
if zanyat == 0:
	s = sum(a)
elif zanyat > 0:
	s = sum(a[:m])
else:
	s = zanyat * d + sum(a)
print(s)


gi = lambda : list(map(int, input().split()))
(n, d) = gi()
l = gi()
(m,) = gi()
print(sum(sorted(l)[:min(m, n)]) - max(0, m - n) * d)


3

def readln():
	return tuple(map(int, input().split()))
(n, d) = readln()
a = sorted(readln())
(m,) = readln()
if m <= n:
	print(sum(a[:m]))
else:
	print(sum(a) - (m - n) * d)


(n, d) = map(int, input().split())
arr = [int(i) for i in input().split()]
m = int(input())
arr.sort()
if m >= n:
	print(sum(arr) - (m - n) * d)
elif m < n:
	print(sum(arr[:m]))


(n, d) = (int(x) for x in input().split(None, 2))
a = [int(x) for x in input().split()]
assert len(a) == n
m = int(input())
if n <= m:
	print(sum(a) - d * (m - n))
else:
	a.sort()
	print(sum(a[:m]))


(n, d) = list(map(int, input().split()))
A = list(map(int, input().split()))
m = int(input())
if m < n:
	A = sorted(A)
	print(sum(A[:m]))
else:
	print(sum(A) - d * (m - n))


(n, d) = [int(i) for i in input().split(' ')]
ai = [int(i) for i in input().split(' ')]
m = int(input())
if m >= n:
	print(sum(ai) - (m - n) * d)
else:
	print(sum(sorted(ai)[:m]))


__copyright__ = ''
__author__ = 'Son-Huy TRAN'
__email__ = 'sonhuytran@gmail.com'
__doc__ = ''
__version__ = '1.0'

def main() -> int:
	(n, d) = map(int, input().split())
	costs = sorted([int(word) for word in input().split()])
	m = int(input())
	profit = 0
	if m <= n:
		profit = sum(costs[:m])
	else:
		profit = sum(costs) - (m - n) * d
	print(profit)
	return 0
exit(main())


(n, d) = map(int, input().split())
a = sorted(list(map(int, input().split())))
m = int(input())
left = m - n
if left > 0:
	print(-d * left + sum(a))
else:
	print(sum(a[:m]))


(n, d) = map(int, input().split())
al = list(map(int, input().split()))
m = int(input())
ans = 0
if m > n:
	ans = sum(al) - (m - n) * d
else:
	al.sort()
	ans = sum(al[:m])
print(ans)


tmp = [int(i) for i in input().split()]
n = tmp[0]
d = tmp[1]
a = [int(i) for i in input().split()]
a.sort()
m = int(input())
out = 0
for i in range(0, m):
	if i < len(a):
		out = out + a[i]
	else:
		out = out - d
print(out)


(racks, fine) = map(int, input().split())
cost = list(map(int, input().split()))
cost.sort()
guests = int(input())
if guests > racks:
	print(sum(cost) - (guests - racks) * fine)
else:
	print(sum(cost[:guests]))


(n, d) = map(int, input().split())
C = list(map(int, input().split()))
m = int(input())
if m > n:
	f = sum(C) - (m - n) * d
	print(f)
else:
	C.sort()
	f = 0
	for i in range(m):
		f += C[i]
	print(f)


(n, d) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
m = int(input())
s = sum(arr[0:m])
penalty = max(0, m - n) * d
print(s - penalty)


(n, d) = map(int, input().split())
a = sorted([int(x) for x in input().split()])
m = int(input())
if m <= n:
	print(sum(a[:m]))
else:
	print(sum(a) - (m - n) * d)


(n, d) = map(int, input().split())
a = list(map(int, input().split()))
m = int(input())
a.sort()
x = sum(a)
if m > n:
	print(x - (m - n) * d)
elif m == n:
	print(x)
else:
	print(sum(a[:m]))


import sys
input = sys.stdin.readline

def gint():
	return int(input())

def gint_arr():
	return list(map(int, input().split()))

def gfloat():
	return float(input())

def gfloat_arr():
	return list(map(float, input().split()))

def pair_int():
	return map(int, input().split())
INF = 1 << 31
MOD = '1000000007'
dx = [-1, 0, 1, 0, -1, 1, 1, -1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]
(n, d) = gint_arr()
a = gint_arr()
a.sort()
m = gint()
res = sum(a[:m])
print(res if m <= n else res - (m - n) * d)


(n, d) = map(int, input().split())
racks = list(map(int, input().split()))
m = int(input())
fine = (m - n) * d
res = -fine if fine > 0 else 0
racks = sorted(racks)
print(res + sum(racks[:m]))


(n, d) = (int(x) for x in input().split())
a = sorted((int(x) for x in input().split()))
m = int(input())
print(sum(a[:m]) - d * max(0, m - n))


(num_hooks, ruble_fine) = map(int, input().split())
hooks = list(map(int, input().split()))
number_customer = int(input())
profit = 0
for i in range(number_customer):
	if len(hooks) > 0:
		profit += min(hooks)
		hooks.remove(min(hooks))
	else:
		profit -= ruble_fine
print(profit)


def main(stdin):
	(n, d) = next(stdin).split()
	(n, d) = (int(n), int(d))
	a_i = sorted(map(int, next(stdin).split()))
	m = int(next(stdin))
	lost = 0
	a_sum = sum((int(a_i[i]) for i in range(min(m, n))))
	if n < m:
		lost = d * (m - n)
	print(a_sum - lost)

def __starting_point():
	import sys
	main(sys.stdin)
__starting_point()


def solution(a, d, m):
	net = 0
	if len(a) >= m:
		a.sort()
		for i in range(m):
			net += a[i]
	else:
		net = sum(a)
		neg = (m - len(a)) * d
		net = net - neg
	print(net)
a = list(map(int, input('').split()))
b = list(map(int, input('').split()))
m = int(input(''))
solution(b, a[1], m)


(_1, __) = map(int, input().split())
s = []
n = 0
for i in map(int, input().split()):
	n += i
	s.append(i)
r = int(input())
if r >= _1:
	print(n - (r - _1) * __)
elif r < _1:
	d = 0
	s = sorted(s)
	for i in range(0, r):
		d += s[i]
	print(d)


(n, d) = tuple(map(int, str.split(input())))
a = sorted(map(int, str.split(input())))
m = int(input())
print(sum(a[:min(m, n)]) - max(0, m - n) * d)


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
Y = lambda : list(map(int, input().split()))
P = lambda : map(int, input().split())
N = lambda : int(input())
(n, d) = P()
a = Y()
m = N()
a.sort()
mx = min(n, m)
ans = sum(a[:mx])
if mx == n:
	ans += (n - m) * d
print(ans)


import sys

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

def iinput():
	return int(input())

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
(n, d) = rinput()
a = list(map(int, input().split()))
a.sort()
m = iinput()
l = m - n
profit = 0
if m < n:
	profit += sum(a[:m])
else:
	profit += sum(a)
	profit -= l * d
print(profit)


a = input().split()
(n, d) = (int(a[0]), int(a[1]))
a = [int(x) for x in input().split()]
m = int(input())
a.sort()
sum = 0
for i in [x for x in range(m) if x < n]:
	sum += a[i]
sum -= (m - i - 1) * d
print(sum)


datos_n_d = input().split()
n = int(datos_n_d[0])
d = int(datos_n_d[1])
costo_gancho = []
datos_gancho = input().split()
for dato in datos_gancho:
	costo_gancho.append(int(dato))
m = int(input())
balance = 0
costo_gancho.sort()
if n >= m:
	for i in range(m):
		balance = balance + costo_gancho[i]
else:
	balance = sum(costo_gancho) - (m - n) * d
print(balance)


import math
(n, d) = str(input()).split()
n = int(n)
d = int(d)
line = str(input()).split()
line = [int(it) for it in line]
line.sort()
m = int(input())
print(sum(line[:min(n, m)]) - d * max(0, m - n))


(n, d) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
m = int(input())
ans = sum(a[:m])
ans -= max(0, m - n) * d
print(ans)


l1 = input()
l1 = l1.split()
n = int(l1[0])
d = int(l1[1])
l = input()
l = l.split()
a = []
s = 0
for i in range(n):
	a.append(int(l[i]))
	s += int(l[i])
m = int(input())
if m >= n:
	print(s - (m - n) * d)
else:
	a.sort()
	s = 0
	i = 0
	while m > 0:
		m -= 1
		s += a[i]
		a.remove(a[i])
	print(s)


(n, d) = map(int, input().split())
s = sorted(map(int, input().split()))
m = int(input())
print(sum(s[:min(n, m)]) - d * max(0, m - n))


I = lambda : [*map(int, input().split())]
(n, d) = I()
a = sorted(I())
r = 0
for i in range(I()[0]):
	r += i < n and a[i] or -d
print(r)


(n, d) = map(int, input().split())
a = list(map(int, input().split()))
m = int(input())
if m <= len(a):
	a.sort()
	a = a[:m]
	print(sum(a))
else:
	temp = m - len(a)
	ans = sum(a) - temp * d
	print(ans)


string = input()
numbers = string.split()
(a, b) = (int(numbers[0]), int(numbers[1]))
string = input()
numbers = sorted(map(int, string.split()))
n = int(input())
p = 0
if n > a:
	p -= (n - a) * b
	n = a
p += sum(numbers[:n])
print(p)


from sys import stdin, stdout
lines = stdin.readlines()
n = int(lines[0].split()[0])
d = int(lines[0].split()[1])
a = [int(x) for x in lines[1].split()]
m = int(lines[2])
ans = 0
if m >= n:
	ans = sum(a) - d * (m - n)
else:
	a = sorted(a)
	ans = sum(a[:m])
print(ans)


I = lambda : map(int, input().split())
(n, d) = I()
a = sorted(I()) + [-d] * 99
print(sum(a[:next(I())]))


(n, d) = [int(j) for j in input().split()]
nums = [int(j) for j in input().split()]
m = int(input())
res = 0
if m > n:
	res = sum(nums) - d * (m - n)
else:
	res = sum(sorted(nums)[:m])
print(res)


(n, d) = map(int, input().split())
lst = list(map(int, input().split()))
m = int(input())
lst.sort()
profit = 0
c = 0
if m < len(lst):
	for i in range(m):
		profit += lst[i]
elif m > len(lst):
	profit = sum(lst) - (m - len(lst)) * d
else:
	profit = sum(lst)
print(profit)


(n, d) = input().strip().split(' ')
(n, d) = (int(n), int(d))
l = list(map(int, input().strip().split(' ')))
m = int(input())
l.sort()
a = 0
b = max(0, m - n) * d
for i in range(min(n, m)):
	a += l[i]
print(a - b)


(n, d) = map(int, input().split())
s = input()
a = s.split(' ')
a = sorted([int(i) for i in a])
m = int(input())
if n == m:
	print(sum(a))
elif n > m:
	print(sum(a[:m]))
else:
	print(sum(a) - (m - n) * d)


(n, d) = tuple(map(int, input().split()))
hooks = list(map(int, input().split()))
m = int(input())
hooks.sort()
s = 0
for i in range(min(len(hooks), m)):
	s += hooks[i]
if m > len(hooks):
	s -= (m - len(hooks)) * d
print(s)


(n, d) = map(int, input().split())
ai = list(map(int, input().split()))
ai.sort()
m = int(input())
if m <= n:
	print(sum(ai[:m]))
else:
	s = sum(ai)
	print(s - (m - n) * d)


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


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


from __future__ import division, print_function
import os, 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 ii():
	return int(input())

def si():
	return input()

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

def msi():
	return map(str, input().strip().split(' '))

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

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scan_int = lambda : int(input())
scan_string = lambda : input().rstrip()
read_list = lambda : list(read())
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

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

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

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

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	(n, d) = read()
	a = read_list()
	a.sort()
	m = scan_int()
	print(sum(a[:min(n, m)]) - d * max(0, m - n))
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')
for i in range(1):
	solve()


(n, d) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
m = int(input())
cost = sum(arr) if n <= m else sum(arr[:m])
cost = cost + -d * (m - n) if n <= m else cost
print(cost)


(n, d) = map(int, input().split())
m = list(map(int, input().split()))
m.sort()
f = int(input())
i = 0
s = 0
while i < n and i < f:
	s += m[i]
	i += 1
if f > n:
	s -= d * (f - n)
print(s)


(n, d) = map(int, input().split())
A = list(map(int, input().split()))
m = int(input())
A.sort()
S = sum(A[:m])
S -= d * max(m - len(A), 0)
print(S)


(n, x) = map(int, input().split())
l = list(map(int, input().split()))
m = int(input())
if m >= n:
	print(sum(l) - (m - n) * x)
else:
	j = sorted(l)
	c = 0
	for i in range(m):
		c += j[i]
	print(c)


import sys

def __starting_point():
	(n, d) = [int(i) for i in sys.stdin.readline().rstrip().split(' ')]
	a_arr = sorted([int(i) for i in sys.stdin.readline().rstrip().split(' ')])
	m = int(sys.stdin.readline().rstrip())
	if m <= n:
		print(sum(a_arr[:m]))
	else:
		print(sum(a_arr) - (m - n) * d)
__starting_point()


(n, d) = input().split()
n = int(n)
d = int(d)
sum = 0
l = input().split()
for i in range(n):
	l[i] = int(l[i])
m = int(input())
p = d * (m - n)
l.sort()
if m > n:
	m = n
else:
	p = 0
for i in range(m):
	sum += l[i]
profit = sum - p
print(profit)


(n, d) = map(int, input().split())
a = list(map(int, input().split()))
m = int(input())
ans = 0
used = [False] * n
for _ in range(min(m, n)):
	minS = max(a) + 1
	for k in range(n):
		if not used[k] and a[k] < minS:
			minS = a[k]
			ind_min = k
	used[ind_min] = True
	ans += a[ind_min]
if m > n:
	ans -= d * (m - n)
print(ans)


from sys import stdin
a = list(map(int, stdin.readline().split()))
n = a[0]
d = a[1]
a = list(map(int, stdin.readline().split()))
m = int(input())
if m >= n:
	print(sum(a) - d * (m - n))
else:
	count = 0
	for i in range(n - m):
		c = max(a)
		del a[a.index(c)]
	print(sum(a))


(a, b) = map(int, input().split())
z = sorted(map(int, input().split()))
m = int(input())
if m < a:
	print(sum(z[0:m]))
else:
	print(sum(z) - (m - a) * b)


(n, d) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
m = int(input())
a.sort()
if m <= n:
	print(sum(a[:m]))
else:
	print(sum(a) - (m - n) * d)


profit = 0
(n, d) = map(int, input().split())
a = [int(x) for x in input().split()]
m = int(input())
if m < n:
	a.sort()
	profit += sum(a[:m])
else:
	profit += sum(a)
	profit -= (m - n) * d
print(profit)


(n, d) = list(map(int, input().split()))
a = list(map(int, input().split()))
m = int(input())
z = 0
k = 0
l = 0
a.sort()
if n == m:
	for i in range(0, a.__len__()):
		z += a[i]
elif m > n:
	for i in range(0, a.__len__()):
		z += a[i]
	z -= (m - n) * d
elif n > m:
	for i in range(0, m):
		z += a[i]
print(z)


(n, d) = map(int, input().split())
l = list(map(int, input().split()))
m = int(input())
l.sort()
if n == m:
	s = sum(l)
elif m > n:
	s = sum(l)
	fine = (m - n) * d
	s = s - fine
else:
	s = sum(l[:m])
print(s)


(n, d) = map(int, input().split())
l = [int(x) for x in input().split()]
m = int(input())
l.sort()
if m <= len(l):
	print(sum(l[:m]))
else:
	print(sum(l) - (m - len(l)) * d)


(hooks, fine) = map(int, input().split())
cost = list(map(int, input().split()))
guests = int(input())
if guests > hooks:
	print(sum(cost) - fine * (guests - hooks))
else:
	print(sum(sorted(cost)[:guests]))


(n, d) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
m = int(input())
a = sorted(a)
if m <= n:
	a = a[0:m]
	print(sum(a))
else:
	e = sum(a)
	print(e - (m - n) * d)


(n, d) = map(int, input().split())
a = list(map(int, input().split()))
m = int(input())
a.sort()
k = 0
s = 0
for i in range(m):
	if i < len(a):
		k += a[s]
		s += 1
	else:
		k -= d
print(k)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
x = int(input())
if x >= a:
	s = sum(l) - (x - a) * b
else:
	s = sum(l[:x])
print(s)


(n, d) = (int(i) for i in input().split())
l = sorted([int(i) for i in input().split()])
m = int(input())
print(sum(l[:min(m, n)]) - max(0, (m - n) * d))


X = list(map(int, input().split()))
Hooks = sorted(list(map(int, input().split())))
Guest = int(input())
(SUM, i) = (0, 0)
while i < X[0] and Guest != 0:
	SUM += Hooks[i]
	Guest -= 1
	i += 1
print(SUM - Guest * X[1])


import sys
import math
(n, d) = [int(x) for x in sys.stdin.readline().split()]
a = [int(x) for x in sys.stdin.readline().split()]
m = int(sys.stdin.readline())
a.sort()
k = 0
s = 0
if m > n:
	k = n
	s = -((m - n) * d)
else:
	k = m
for i in range(k):
	s += a[i]
print(s)


import math

def main_function():
	(n, d) = [int(i) for i in input().split(' ')]
	a = sorted([int(i) for i in input().split(' ')])
	m = int(input())
	if m == n:
		print(sum(a))
	elif m < n:
		print(sum(a[:m]))
	else:
		print(sum(a) - d * (m - n))
main_function()


(h, t) = map(int, input().split())
a = list(map(int, input().split()))
p = int(input())
a.sort()
if h == p:
	print(sum(a))
elif h < p:
	ans = 0
	for i in range(h):
		ans += a[i]
	ans -= (p - len(a)) * t
	print(ans)
else:
	ans = 0
	for i in range(p):
		ans += a[i]
	print(ans)


line = input().split()
n = int(line[0])
d = int(line[1])
line = [int(i) for i in input().split()]
line.sort()
m = int(input())
count = 0
for a in range(m):
	if a < len(line):
		count += line[a]
	else:
		count -= d
print(count)


class CodeforcesTask368ASolution:

	def __init__(self):
		self.result = ''
		self.n_d = []
		self.hooks = []
		self.guests = 0

	def read_input(self):
		self.n_d = [int(x) for x in input().split(' ')]
		self.hooks = [int(x) for x in input().split(' ')]
		self.guests = int(input())

	def process_task(self):
		self.hooks.sort()
		profit = max(0, self.guests - self.n_d[0]) * -self.n_d[1] + sum(self.hooks[:min(self.n_d[0], self.guests)])
		self.result = str(profit)

	def get_result(self):
		return self.result
Solution = CodeforcesTask368ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, d) = map(int, input().split())
l1 = list(map(int, input().split()))
l1.sort()
m = int(input())
t = sum(l1[:m])
t = t - max(0, (m - n) * d)
print(t)


I = lambda : map(int, input().split())
(n, d) = I()
A = sorted(I())
m = int(input())
print(sum(A[:m]) - max(0, (m - n) * d))


def solve(n, d, arr, m):
	tot = 0
	curr = 0
	arr.sort()
	for i in range(m):
		if curr < n:
			cost = arr[curr]
			tot += cost
			curr += 1
		else:
			tot -= d
	return tot

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


a = input()
b = input()
c = int(input())
a1 = a.split()
a2 = [int(d) for d in a1]
b1 = b.split()
b2 = [int(d) for d in b1]
no_of_hooks = a2[0]
loss = a2[1]
b2.sort()
if c == no_of_hooks:
	profit = sum(b2)
elif c > no_of_hooks:
	profit = sum(b2) + -(c - no_of_hooks) * loss
elif c < no_of_hooks:
	profit = sum(b2[:c])
print(profit)


import sys
n_d = sys.stdin.readline().split()
n = int(n_d[0])
d = int(n_d[1])
lista = sys.stdin.readline().split()
for i in range(n):
	lista[i] = int(lista[i])
m = int(sys.stdin.readline())
count = 0
lista = sorted(lista)
lista.reverse()
while m > 0:
	if len(lista) > 0:
		count += lista.pop()
	else:
		count -= d
	m -= 1
print(count)