Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is a_{i}, and after a week of discounts its price will be b_{i}.

Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.

Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items.


-----Input-----

In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·10^5, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now.

The second line contains sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^4) — prices of items during discounts (i.e. right now).

The third line contains sequence of integers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 10^4) — prices of items after discounts (i.e. after a week).


-----Output-----

Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now.


-----Examples-----
Input
3 1
5 4 6
3 1 5

Output
10

Input
5 3
3 4 7 10 3
4 5 5 12 5

Output
25



-----Note-----

In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.

In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.

Difficulty: EASY
Tags: Greedy algorithms

Sorting

Constructive algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
(n, k) = map(int, input().split())
l = [(int(i) - int(j), int(i), int(j)) for (i, j) in zip(input().split(), input().split())]
l.sort()
ans = 0
for i in range(n):
	if k > 0:
		ans += l[i][1]
		k -= 1
	else:
		ans += min(l[i][1:])
print(ans)


R = lambda : list(map(int, input().split()))
(n, k) = R()
A = R()
B = R()
items = list(zip(A, B))
items = sorted(items, key=lambda x: x[0] - x[1])
res = 0
for i in range(k):
	res += items[i][0]
for i in range(k, len(items)):
	res += min(items[i][0], items[i][1])
print(res)


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


(n, k) = input().split()
(n, k) = (int(n), int(k))
(a, b) = (input().split(), input().split())
dif = []
s = 0
for i in range(0, n):
	dif.append(int(a[i]) - int(b[i]))
	s += int(a[i])
dif = sorted(dif)
for i in range(k, n):
	if dif[i] > 0:
		s -= dif[i]
print(s)


R = lambda : list(map(int, input().split()))
(n, k) = R()
A = R()
B = R()
sum = 0
iteams = list(zip(A, B))
iteams = sorted(iteams, key=lambda x: x[0] - x[1])
for i in range(0, n):
	if i < k:
		sum = sum + iteams[i][0]
	else:
		sum = sum + min(iteams[i][0], iteams[i][1])
print(sum)


(n, k) = map(int, input().split())
l_d = list(map(int, input().split()))
l_a = list(map(int, input().split()))
l_pd = list()
for i in range(n):
	l_pd.append([l_d[i] - l_a[i], i])
l_pd.sort()
t_b = 0
p = 0
for l in l_pd:
	if l[0] <= 0 or t_b < k:
		t_b += 1
		p += l_d[l[1]]
	else:
		p += l_a[l[1]]
print(p)


(n, k) = map(int, input().strip().split(' '))
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
p = 0
price = 0
for i in range(n):
	if a[i] <= b[i]:
		price += a[i]
		p += 1
		a[i] = -1
		b[i] = -1
if p >= k:
	for i in range(n):
		if b[i] >= 0:
			price += b[i]
else:
	diff = []
	for i in range(n):
		if a[i] > 0:
			e = a[i] - b[i]
			q = []
			q.append(e)
			q.append(i)
			diff.append(q)
	diff.sort()
	for i in range(k - p):
		price += a[diff[i][1]]
	for i in range(k - p, len(diff)):
		price += b[diff[i][1]]
print(price)


(n, k) = map(int, input().split())
li1 = list(map(int, input().split()))
li2 = list(map(int, input().split()))
li3 = []
for i in range(0, n):
	li3.append([li1[i] - li2[i], li1[i], li2[i]])
li3 = sorted(li3)
i = 0
ans = 0
while i < n:
	if i < k or li3[i][0] < 0:
		ans += li3[i][1]
		i += 1
	else:
		break
while i < n:
	ans += li3[i][2]
	i += 1
print(ans)


def takeSecond(elem):
	return elem[2]
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
for i in range(n):
	x += [(a[i], b[i], a[i] - b[i])]
x = sorted(x, key=takeSecond)
s = 0
for i in range(n):
	if i < k:
		s += x[i][0]
	else:
		s += min(x[i][1], x[i][0])
print(s)


X = list(map(int, input().split()))
This = list(map(int, input().split()))
That = list(map(int, input().split()))
Whole = sorted(zip(This, That), key=lambda x: x[0] - x[1])
Sum = 0
for i in range(X[0]):
	if X[1] > 0:
		Sum += Whole[i][0]
		X[1] -= 1
	else:
		Sum += min(Whole[i][0], Whole[i][1])
print(Sum)


from sys import stdin, stdout
(n, k) = map(int, stdin.readline().rstrip().split())
a = stdin.readline().rstrip().split()
a = [int(num) for num in a]
b = stdin.readline().rstrip().split()
b = [int(num) for num in b]
costDiff = [b[i] - a[i] for i in range(n)]
sortedCostDiff = sorted(costDiff, reverse=True)
savingMade = len([i for i in costDiff if i >= 0])
if savingMade >= k:
	totalSpend = 0
	for i in range(n):
		totalSpend += min([a[i], b[i]])
else:
	maxCost = sortedCostDiff[k - 1]
	cutoffSortedDiff = sortedCostDiff[:k]
	minCount = cutoffSortedDiff.count(maxCost)
	totalSpend = 0
	for i in range(n):
		if b[i] - a[i] > maxCost:
			totalSpend += a[i]
		elif b[i] - a[i] == maxCost and minCount > 0:
			totalSpend += a[i]
			minCount -= 1
		else:
			totalSpend += b[i]
print(totalSpend)


(n, k) = map(int, input().split())
cnt = [[0 for i in range(0, 3)] for j in range(0, n)]
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(0, n):
	cnt[i][0] = b[i] - a[i]
	cnt[i][1] = a[i]
	cnt[i][2] = b[i]
cnt.sort()
ans = 0
for i in range(n - 1, n - k - 1, -1):
	ans += cnt[i][1]
for i in range(n - k - 1, -1, -1):
	ans += min(cnt[i][1], cnt[i][2])
print(ans)


(n, k) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
arr = [(ai - bi, ai, bi) for (ai, bi) in zip(a, b)]
arr.sort()
i = 0
total = 0
while i < n and (i < k or arr[i][0] < 0):
	total += arr[i][1]
	i += 1
for j in range(i, n):
	total += arr[j][2]
print(total)


R = lambda : list(map(int, input().split()))
(n, k) = R()
a = R()
b = R()
ans = sum(b)
for i in range(n):
	a[i] -= b[i]
a = sorted(a)
for i in range(n):
	if i < k or a[i] < 0:
		ans += a[i]
	else:
		break
print(ans)


(n, k) = list(map(int, input().split()))
o = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = sum(o)
diff = sorted([y - x for (x, y) in zip(o, a)], reverse=True)
for i in diff[k:]:
	if i >= 0:
		pass
	else:
		ans += i
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = list(map(lambda x, y: x - y, a, b))
d.sort()
kk = sum([x < 0 for x in d])
kk = max(k, kk)
print(sum(b) + sum(d[:kk]))


def solve():
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = [a[0] - a[1] for a in zip(A, B)]
	D = list(zip(list(range(N)), C))
	D.sort(key=lambda tup: tup[1])
	cost = 0
	for i in range(K):
		cost += A[D[i][0]]
	j = K
	while j < N and D[j][1] <= 0:
		cost += A[D[j][0]]
		j += 1
	for i in range(j, N):
		cost += B[D[i][0]]
	print(cost)
solve()


import math
from collections import defaultdict

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

def solve():
	(n, k) = input_ints()
	a = input_ints()
	b = input_ints()
	x = [(a[i] - b[i], b[i]) for i in range(n)]
	x = sorted(x)
	ans = 0
	for (i, p) in enumerate(x):
		if i < k or p[0] <= 0:
			ans += p[0] + p[1]
		else:
			ans += p[1]
	print(ans)
solve()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [(a[i], b[i]) for i in range(n)]
c.sort(key=lambda x: x[0] - x[1])
sm = 0
for i in range(k):
	sm += c[i][0]
for i in range(k, n):
	sm += min(c[i][0], c[i][1])
print(sm)


(_, k) = map(int, input().split())
prices = sorted(((a - b, a, b) for (a, b) in zip(map(int, input().split()), map(int, input().split()))))
print(sum((a for (_, a, _) in prices[:k])) + sum((min(a, b) for (_, a, b) in prices[k:])))


def f(c):
	return c[0]
ans = 0
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append([a[i] - b[i], a[i], b[i]])
c.sort(key=f)
if k != 0:
	for i in range(k):
		ans += c[i][1]
	i += 1
else:
	i = 0
while i != n and c[i][0] < 0:
	ans += c[i][1]
	i += 1
for j in range(i, n):
	ans += c[j][2]
print(ans)


(N, k) = list(map(int, input().strip().split(' ')))
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
diff = [x - y for (x, y) in zip(a, b)]
s = sorted(zip(a, b, diff), key=lambda x: x[2])
on_discount = [x[0] for x in s[:k]]
later = [x[1] if x[2] > 0 else x[0] for x in s[k:]]
print(sum(on_discount + later))


(n, k) = [int(s) for s in input().split()]
now = [int(s) for s in input().split()]
after = [int(s) for s in input().split()]
prices = [a for a in zip(now, after)]
prices = sorted(prices, key=lambda x: x[0] - x[1])
print(sum([price[0] for price in prices[:k]]) + sum([min(price) for price in prices[k:]]))


(n, k) = map(int, input().split())
a = [int(y) for y in input().split()]
b = [int(y) for y in input().split()]
diff = []
for i in range(n):
	diff.append([a[i] - b[i], i])
diff.sort()
su = 0
visited = [0] * n
for i in range(k):
	su += a[diff[i][1]]
	visited[diff[i][1]] = 1
for i in range(n):
	if visited[i] == 0:
		su += min(a[i], b[i])
print(su)


def main():
	(n, k) = map(int, input().split())
	a = map(int, input().split())
	b = map(int, input().split())
	d = list(zip(a, b))
	d = sorted(d, key=lambda x: x[0] - x[1])
	ans = sum((x[0] for x in d[:k]))
	ans += sum((min(x[0], x[1]) for x in d[k:]))
	print(ans)
main()


(x, y) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(x):
	c.append(a[i] - b[i])
c.sort()
j = 0
k = sum(b)
while j < x:
	if j < y or c[j] < 0:
		k += c[j]
		j += 1
	else:
		break
print(k)


(n, k) = input().split()
(n, k) = (int(n), int(k))
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
ans = sum(bb)
li = sorted([a - b for (a, b) in zip(aa, bb)])
for i in range(n):
	if i < k or li[i] < 0:
		ans += li[i]
	else:
		break
print(ans)


from sys import stdin, stdout
(n, k) = map(int, stdin.readline().split())
pricesb = list(map(int, stdin.readline().split()))
pricesa = list(map(int, stdin.readline().split()))
cnt = []
for i in range(n):
	cnt.append((pricesb[i] - pricesa[i], i))
cnt.sort()
ans = 0
for i in range(n):
	if i < k or cnt[i][0] < 0:
		ans += pricesb[cnt[i][1]]
	else:
		ans += pricesa[cnt[i][1]]
stdout.write(str(ans))


(n, k) = map(int, input().split())
t = list(map(int, input().split()))
c = list(map(int, input().split()))
d = [t[i] - c[i] for i in range(len(t)) if 0 < t[i] - c[i]]
s = 0
for i in t:
	s += i
d.sort()
while n - k and d:
	n -= 1
	s -= d.pop()
print(s)


(n, k) = input().split()
(n, k) = (int(n), int(k))
sum = 0
(now, then) = (input().split(), input().split())
diff = []
for i in range(0, n):
	diff.append(int(now[i]) - int(then[i]))
	sum += int(now[i])
diff = sorted(diff)
for i in range(k, n):
	if diff[i] > 0:
		sum -= diff[i]
print(sum)


def min_price(n, k, l, m):
	s = sum(m)
	for i in range(n):
		l[i] -= m[i]
	l.sort()
	for i in range(n):
		if i < k or l[i] < 0:
			s += l[i]
		else:
			break
	return s
R = lambda : list(map(int, input().split()))
(n, k) = R()
l = R()
m = R()
print(min_price(n, k, l, m))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
cost = 0
l = sorted(list(zip(a, b)), key=lambda x: x[0] - x[1])
for i in l:
	if c < k:
		c += 1
		cost += i[0]
	elif i[0] < i[1]:
		cost += i[0]
	else:
		cost += i[1]
print(cost)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = sum(b)
for i in range(n):
	a[i] -= b[i]
a = sorted(a)
for i in range(n):
	if i < k or a[i] < 0:
		ans += a[i]
	else:
		exit(print(ans))
print(ans)


(n, k) = map(int, input().strip().split(' '))
lst1 = list(map(int, input().strip().split(' ')))
lst2 = list(map(int, input().strip().split(' ')))
s = 0
c = 0
l3 = []
for j in range(n):
	if lst1[j] <= lst2[j]:
		s += lst1[j]
		c += 1
	else:
		s += lst2[j]
		l3.append(lst1[j] - lst2[j])
if c >= k:
	print(s)
else:
	l3.sort()
	for j in range(k - c):
		s += l3[j]
	print(s)


read = lambda : map(int, input().split())
(n, k) = read()
a = list(read())
b = list(read())
c = [[a[i] - b[i], i] for i in range(len(a))]
c.sort()
s = 0
i = 0
A = []
while i < len(a) and (c[i][0] <= 0 or i < k):
	A.append(c[i][1])
	i += 1
B = list(set([i for i in range(n)]) - set(A))
print(sum([a[i] for i in A]) + sum([b[i] for i in B]))


(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l = list(zip(l1, l2))
l.sort(key=lambda x: x[0] - x[1])
s = 0
c = 0
for i in range(n):
	if l[i][0] - l[i][1] <= 0:
		s += l[i][0]
		c += 1
	elif c < k:
		s += l[i][0]
		c += 1
	else:
		s += l[i][1]
print(s)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
(n, k) = RMI()
acst = RMI()
sums = sum(acst)
bcst = RMI()
bcst = [bcst[i] - acst[i] for i in range(n)]
bcst = sorted(bcst)[:n - k]
while bcst and bcst[-1] > 0:
	bcst.pop()
print(sums + sum(bcst))


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


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
thelist = []
for i in range(len(a)):
	nextentry = (a[i] - b[i], a[i], b[i])
	thelist.append(nextentry)
thelist.sort()
answer = 0
index = 0
while index < k:
	answer += thelist[index][1]
	index += 1
while index < len(a) and thelist[index][0] < 0:
	answer += thelist[index][1]
	index += 1
while index < len(a):
	answer += thelist[index][2]
	index += 1
print(answer)


from heapq import heappush, heappop
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
q = []
for i in range(n):
	heappush(q, (a[i] - b[i], a[i], b[i]))
res = 0
for _ in range(k):
	res += heappop(q)[1]
while q:
	t = heappop(q)
	res += min(t[1], t[2])
print(res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = sum(a)
ans = s
c = sorted([b[i] - a[i] for i in range(n)])
k = n - k
for i in range(k):
	s += c[i]
	if ans > s:
		ans = s
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
items = []
for i in range(0, n):
	item = (b[i] - a[i], a[i], b[i])
	items.append(item)
items = sorted(items, key=lambda x: int(x[0]), reverse=True)
ans = 0
for i in range(0, n):
	if i < k:
		ans = ans + items[i][1]
	else:
		ans = ans + min(items[i][1], items[i][2])
print(ans)


from itertools import takewhile

def readline():
	return [int(c) for c in input().split()]

def main():
	(n, k) = readline()
	(a, b) = (readline(), readline())
	diff = sorted((x - y for (x, y) in zip(a, b)))
	a_items = max(k, sum((1 for _ in takewhile(lambda x: x <= 0, diff))))
	print(sum(b) + sum(diff[:a_items]))
main()


(n, k) = map(int, input().split())
(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
d = sorted([a[i] - b[i] for i in range(n)])
t = sum(d[:k])
while k < len(d) and d[k] < 0:
	t += d[k]
	k += 1
print(sum(b) + t)


import collections
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = collections.defaultdict(int)
(buy, ans) = (0, 0)
l = []
for i in range(n):
	if a[i] <= b[i]:
		buy += 1
		d[i] = 1
		ans += a[i]
	else:
		l.append((a[i] - b[i], i))
if k - buy > 0:
	l.sort()
	for i in range(k - buy):
		ans += a[l[i][1]]
		d[l[i][1]] = 1
for i in range(n):
	if i not in d:
		ans += b[i]
print(ans)


from bisect import bisect
(n, k) = list(map(int, input().split()))
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
dd = sorted((a - b for (a, b) in zip(aa, bb)))
k = max(k, bisect(dd, 0))
print(sum(bb) + sum(dd[:k]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = list()
for i in range(n):
	t.append([a[i] - b[i], i])
t.sort()
ind = 0
summa = 0
bo = True
while ind < n:
	if t[ind][0] > 0 and ind >= k:
		break
	summa += a[t[ind][1]]
	ind += 1
for i in range(ind, n):
	summa += b[t[i][1]]
print(summa)


(n, k) = [int(x) for x in input().split()]
discounted = [int(x) for x in input().split()]
regular = [int(x) for x in input().split()]
prices = zip(discounted, regular)
prices = sorted(prices, key=lambda x: x[0])
prices = sorted(prices, key=lambda x: x[0] - x[1])
k_cost = sum((x[0] for x in prices[:k]))
after_k_cost = 0
idx = -1
for (i, price) in enumerate(prices[k:]):
	if price[0] < price[1]:
		after_k_cost += price[0]
		idx = i
idx += k + 1
after_discount_cost = sum((x[1] for x in prices[idx:]))
print(k_cost + after_k_cost + after_discount_cost)


(n, k) = map(int, input().split())
x1 = list(map(int, input().split()))
x2 = list(map(int, input().split()))
a = n * [0]
for i in range(n):
	a[i] = [x1[i], x2[i]]
a.sort(key=lambda a: a[0] - a[1])
ans = 0
for j in range(n):
	if k > 0 and a[j][0] - a[j][1] >= 0:
		ans += max(a[j])
	else:
		ans += min(a[j])
	k -= 1
print(ans)


from sys import stdin, stderr

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

def print_err(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def solve(n, k, a, b):
	ps = []
	for ix in range(n):
		ps.append((a[ix] - b[ix], a[ix], b[ix]))
	ps.sort()
	out = 0
	for ix in range(n):
		if ps[ix][0] <= 0 or ix < k:
			out += ps[ix][1]
		else:
			out += ps[ix][2]
	return out

def run():
	(n, k) = readInts()
	a = list(readInts())
	b = list(readInts())
	print(solve(n, k, a, b))
run()


(n, k) = map(int, input().split())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
sm = sum(a2)
diff = []
for i in range(n):
	diff.append(a1[i] - a2[i])
diff.sort()
for i in range(n):
	if i < k or diff[i] < 0:
		sm += diff[i]
print(sm)


def ans(k, a1, a2):
	d = [0] * len(a1)
	for i in range(len(a1)):
		d[i] = a1[i] - a2[i]
	d.sort()
	sum = 0
	for i in a1:
		sum = sum + i
	for i in range(len(d)):
		if k != 0:
			k = k - 1
		elif d[i] > 0:
			sum = sum - d[i]
	return sum
(n, k) = map(int, input().split(' '))
a1 = list(map(int, input().split(' ')))
a2 = list(map(int, input().split(' ')))
print(ans(k, a1, a2))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
offsets = [None] * n
for i in range(n):
	offsets[i] = a[i] - b[i]
offsets.sort()
minus_range = n
for i in range(n):
	if offsets[i] >= 0:
		minus_range = i
		break
print(sum(b) + sum(offsets[:max(k, minus_range)]))


(n, k) = map(int, input().split())
Discount = list(map(int, input().split()))
Normal = list(map(int, input().split()))
Sort = []
money = 0
MARK = [False] * len(Discount)
(Bestdiscount, bestind) = (Discount[0] - Normal[0], 0)
td = 0
for i in range(len(Discount)):
	if Discount[i] <= Normal[i]:
		td += 1
		MARK[i] = True
		money += Discount[i]
	else:
		Sort.append((Discount[i] - Normal[i], i))
Sort.sort()
if td < k:
	for i in range(k - td):
		money += Discount[Sort[i][1]]
		MARK[Sort[i][1]] = True
for i in range(len(Discount)):
	if not MARK[i]:
		money += Normal[i]
print(money)


(m, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
paidmoney = sum(b)
c = sorted(list(map(lambda x, y: x - y, a, b)))
for i in range(m):
	if i < k or c[i] < 0:
		paidmoney += c[i]
	else:
		break
print(paidmoney)


(n, k) = map(int, input().split())
now = list(map(int, input().split()))
ltr = list(map(int, input().split()))
cmb = [(now[i], ltr[i]) for i in range(n)]
cmb.sort(key=lambda x: x[0] - x[1])
ans = sum((x[0] for x in cmb[:k]))
for i in range(k, n):
	ans += min(cmb[i][0], cmb[i][1])
print(ans)


import sys

def make_gen(str):
	arr = str.split(' ')
	for item in arr:
		yield int(item)
s = input()
s = make_gen(s)
n = next(s)
k = next(s)
disc_price = [0] * n
norm_price = [0] * n
s = input()
s = make_gen(s)
for i in range(0, n):
	disc_price[i] = next(s)
s = input()
s = make_gen(s)
for i in range(0, n):
	norm_price[i] = next(s)
total = sum(norm_price)
new_price = []
for i in range(0, n):
	new_price.append(norm_price[i] - disc_price[i])
new_price.sort(reverse=True)
win_sum = 0
for i in range(0, k):
	win_sum += new_price[i]
while k < n and new_price[k] > 0:
	win_sum += new_price[k]
	k += 1
print(total - win_sum)


import sys
fin = sys.stdin
fout = sys.stdout
(n, k) = map(int, fin.readline().split())
a = list(map(int, fin.readline().split()))
b = list(map(int, fin.readline().split()))
diff = [0] * n
for i in range(n):
	diff[i] = (a[i] - b[i], i)
diff.sort()
ans = 0
for i in range(n):
	if i < k:
		ans += a[diff[i][1]]
	elif diff[i][0] < 0:
		ans += a[diff[i][1]]
	else:
		ans += b[diff[i][1]]
fout.write(str(ans))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
for i in range(n):
	c[i] = [a[i] - b[i], i]
c.sort()
s = 0
for i in range(k):
	ind = c[i][1]
	s += a[ind]
for i in range(k, n):
	ind = c[i][1]
	s += min(a[ind], b[ind])
print(s)


(n, k) = map(int, input().split())
pn = list(map(int, input().split()))
pl = list(map(int, input().split()))
diff = [pn[i] - pl[i] for i in range(len(pn))]
diff = sorted(diff)
t = sum(diff[:k])
while k < len(diff) and diff[k] < 0:
	t += diff[k]
	k += 1
print(sum(pl) + t)


from sys import stdin
(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in stdin.readline().split()]
b = [int(x) for x in stdin.readline().split()]
c = []
for i in range(n):
	c.append((a[i] - b[i], i))
c = sorted(c)
ans = 0
i = 0
while i < n and c[i][0] <= 0:
	ans += a[c[i][1]]
	i += 1
if i < k:
	while i < k:
		ans += a[c[i][1]]
		i += 1
while i < n:
	ans += b[c[i][1]]
	i += 1
print(ans)


(n, k) = map(int, input().split())
d = list(map(int, input().split()))
nd = list(map(int, input().split()))
diff = []
for i in range(n):
	diff.append((d[i] - nd[i], i))
ans = 0
diff = sorted(diff, key=lambda x: x[0])
for i in range(k):
	(temp, ind) = diff[i]
	ans += d[ind]
for i in range(k, n):
	(temp, ind) = diff[i]
	if temp < 0:
		ans += d[ind]
	else:
		ans += nd[ind]
print(ans)


(n, k) = (int(_) for _ in input().split(' '))
a = [int(_) for _ in input().split(' ')]
b = [int(_) for _ in input().split(' ')]
total = 0
now = 0
for i in range(n):
	if a[i] <= b[i]:
		now += 1
		total += a[i]
	else:
		total += b[i]
if now >= k:
	print(total)
else:
	diff = [b_i - a_i for (a_i, b_i) in zip(a, b)]
	diff = [d for d in diff if d < 0]
	diff.sort(reverse=True)
	for j in range(k - now):
		total += -diff[j]
	print(total)


(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
ar1 = list(map(int, input().split()))
arr = []
for i in range(n):
	arr.append([ar[i] - ar1[i], ar[i], ar1[i]])
ans = 0
arr = sorted(arr)
for i in range(n):
	if i < k:
		ans += arr[i][1]
	else:
		ans += min(arr[i][1], arr[i][2])
print(ans)


a = input().split()
n = int(a[0])
k = int(a[1])
a = list(map(int, input().split()))
b = list(map(int, input().split()))
danger = []
total = 0
for x in range(0, n):
	if b[x] < a[x]:
		total = total + b[x]
		danger.append(a[x] - b[x])
	else:
		total = total + a[x]
danger.sort()
for x in range(0, k + len(danger) - n):
	total = total + danger[x]
print(total)


r = lambda : list(map(int, input().split()))
(n, now) = r()
cost = r()
nextWeek = r()
dif = sorted([(i, t[0] - t[1]) for (i, t) in enumerate(zip(cost, nextWeek))], key=lambda x: x[1])
total = 0
i = 0
while i < n and (i < now or dif[i][1] < 0):
	total += cost[dif[i][0]]
	i += 1
total += sum((nextWeek[x[0]] for x in dif[i:]))
print(total)


final = 0
(n, k) = input().split()
n = int(n)
k = int(k)
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
Diff = []
added = []
for i in range(len(A)):
	temp = 0
	added.append(temp)
for i in range(len(A)):
	temp = B[i] - A[i]
	Diff.append(temp)
if k == 0:
	for i in range(len(Diff)):
		if Diff[i] >= 0:
			final = final + A[i]
		else:
			final = final + B[i]
	print('{}'.format(final))
else:
	for i in range(len(Diff)):
		if Diff[i] >= 0:
			final = final + A[i]
			added[i] = 1
	ans = sorted(range(len(Diff)), key=lambda i: Diff[i])[-k:]
	for i in range(len(ans)):
		if Diff[ans[i]] < 0:
			final = final + A[ans[i]]
			added[ans[i]] = 1
	for i in range(len(A)):
		if added[i] == 0:
			final = final + B[i]
	print('{}'.format(final))


(var1, var2) = input().split()
(var1, var2) = [int(var1), int(var2)]
p1 = input().split()
p2 = input().split()
p1 = [int(i) for i in p1]
p2 = [int(i) for i in p2]
df = [p1[i] - p2[i] for i in range(0, var1)]
s = sorted(df)
sumx = sum(p2)
for i in range(var1):
	if s[i] > 0 and i >= var2:
		break
	sumx = sumx + s[i]
print(sumx)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
wynik = 0
lista = []
for x in range(n):
	wynik = wynik + b[x]
	roznica = a[x] - b[x]
	if roznica < 0:
		wynik = wynik + roznica
		k = k - 1
	else:
		lista.append(roznica)
lista.sort()
for x in range(len(lista)):
	if k > 0:
		wynik = wynik + lista[x]
		k = k - 1
print(wynik)


import math as mt
import sys, string
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(n, k) = M()
a = L()
b = L()
l = []
for i in range(n):
	l.append((a[i] - b[i], a[i], i))
l.sort(key=lambda x: x[0])
i = 0
ans = 0
while i < k:
	ans += l[i][1]
	i += 1
while k < n:
	ans += min(a[l[k][2]], b[l[k][2]])
	k += 1
print(ans)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = []
for i in range(n):
	a[i] -= b[i]
	c.append(i)
c = sorted(c, key=lambda x: a[x])
s = 0
for i in range(n):
	if i < k or a[c[i]] < 0:
		s += a[c[i]] + b[c[i]]
	else:
		s += b[c[i]]
print(s)


read = lambda : map(int, input().split())
(n, k) = read()
a = list(read())
b = list(read())
c = [(a[i], b[i]) for i in range(n)]
c.sort(key=lambda x: x[0] - x[1])
ans = sum((c[i][0] for i in range(k)))
for i in range(k, n):
	ans += min(c[i][0], c[i][1])
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(zip(a, b))
c = sorted(c, key=lambda d: d[0] - d[1])
sum = 0
i = 0
co = 0
while i < len(a):
	if c[i][0] <= c[i][1]:
		sum += c[i][0]
		co += 1
	elif co >= k:
		sum += c[i][1]
		co += 1
	else:
		sum += c[i][0]
		co += 1
	i += 1
print(sum)


class Compra:

	def __init__(self, hoje, amanha):
		self.hoje = hoje
		self.amanha = amanha

	def __repr__(self):
		return '({}, {})'.format(self.hoje, self.amanha)

	def __lt__(self, other):
		return self.amanha - self.hoje < other.amanha - other.hoje
(n, k) = map(int, input().split())
vetor_A = list(map(int, input().split()))
vetor_B = list(map(int, input().split()))
lista = [Compra(a, b) for (a, b) in zip(vetor_A, vetor_B)]
lista.sort(reverse=True)
ans = 0
for c in lista:
	if c.hoje < c.amanha or k > 0:
		ans += c.hoje
		k -= 1
	else:
		ans += c.amanha
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
m = list(map(int, input().split()))
c = 0
s = 0
for i in range(n):
	if l[i] <= m[i]:
		s += l[i]
		c += 1
if c >= k:
	for i in range(n):
		if l[i] > m[i]:
			s += m[i]
	print(s)
else:
	r = k - c
	p = []
	for i in range(n):
		if l[i] > m[i]:
			p.append((abs(l[i] - m[i]), i))
	p.sort()
	for i in range(r):
		s += l[p[i][1]]
		m[p[i][1]] = 0
	for i in range(n):
		if l[i] > m[i]:
			s += m[i]
	print(s)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
for i in range(n):
	C.append((A[i] - B[i], A[i]))
C.sort()
ans = 0
for i in range(n):
	if C[i][0] <= 0:
		ans += C[i][1]
		k -= 1
	elif k > 0:
		ans += C[i][1]
		k -= 1
	else:
		ans += C[i][1] - C[i][0]
print(ans)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
res = [0 for i in range(n)]
for i in range(n):
	res[i] = a[i] - b[i]
(res, a, b) = zip(*sorted(zip(res, a, b)))
(res, a, b) = [list(t) for t in zip(*sorted(zip(res, a, b)))]
add = 0
c = 0
for i in range(n):
	if res[i] > 0:
		if c >= k:
			add += b[i]
		if c < k:
			add += a[i]
			c += 1
	elif res[i] <= 0:
		add += a[i]
		c += 1
print(add)


import sys
from os import path
if path.exists('input.txt') and path.exists('output.txt'):
	sys.stdout = open('output.txt', 'w')
	sys.stdin = open('input.txt', 'r')

def main():
	(n, k) = (int(i) for i in input().split())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	diffs = sorted([a[i] - b[i] for i in range(n)])
	ans = sum(a)
	for diff in diffs:
		if diff < 0 or k > 0:
			k -= 1
		else:
			ans -= diff
	print(ans)
main()


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
que = [0] * n
for j in range(n):
	que[j] = [A[j] - B[j], j]
que.sort()
ans = 0
for j in range(n):
	if que[j][0] <= 0:
		k -= 1
		ans += A[que[j][1]]
	elif k > 0:
		k -= 1
		ans += A[que[j][1]]
	else:
		j -= 1
		break
for i in range(j + 1, n):
	ans += B[que[i][1]]
print(ans)


import sys
from itertools import accumulate

def debug(x, table):
	for (name, val) in table.items():
		if x is val:
			print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
			return None

def solve():
	(n, k) = map(int, input().split())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	sumB = sum(B)
	dif = [a - b for (a, b) in zip(A, B)]
	dif.sort()
	dif = [0] + list(accumulate(dif))
	ans = float('inf')
	for i in range(k, n + 1):
		ans = min(ans, sumB + dif[i])
	print(ans)

def __starting_point():
	solve()
__starting_point()


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


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(len(a)):
	c.append([a[i] - b[i], a[i], b[i]])
c = sorted(c)
l = 0
for i in range(len(c)):
	if c[i][0] <= 0:
		l += c[i][1]
	elif i < k:
		l += c[i][1]
	else:
		l += c[i][2]
print(l)


def buy(n, k, a, b):
	dif = [(a[i] - b[i], i) for i in range(n)]
	dif.sort()
	cost = 0
	for i in range(k):
		cost += a[dif[i][1]]
	for j in range(k, n):
		if a[dif[j][1]] < b[dif[j][1]]:
			cost += a[dif[j][1]]
		else:
			cost += b[dif[j][1]]
	return cost
(c, d) = map(int, input().strip().split())
e = list(map(int, input().strip().split()))
f = list(map(int, input().strip().split()))
print(buy(c, d, e, f))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([(a[i] - b[i], a[i], b[i]) for i in range(n)])
total = 0
for e in c[:k]:
	total += e[1]
for e in c[k:]:
	total += min(e[1], e[2])
print(total)


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [(ai, ai - bi) for (ai, bi) in zip(a, b)]
c.sort(key=lambda x: x[1])
s = 0
for i in range(n):
	if i < k or c[i][1] <= 0:
		s += c[i][0]
	else:
		s += c[i][0] - c[i][1]
print(s)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = sorted([a[i] - b[i] for i in range(n)])
s = sum(b)
for i in range(n):
	if i >= k and c[i] >= 0:
		break
	s += c[i]
print(s)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = []
for i in range(n):
	arr.append([a[i], b[i], b[i] - a[i]])
arr = sorted(arr, key=lambda item: item[2], reverse=True)
ans = 0
for i in range(k):
	ans += arr[i][0]
i = k
while i < n:
	if arr[i][2] > 0:
		ans += arr[i][0]
	else:
		break
	i += 1
for j in range(i, n):
	ans += arr[j][1]
print(ans)


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
for i in range(n):
	a[i] = int(a[i])
	b[i] = int(b[i])
	a[i] = [a[i] - b[i], a[i]]
a = sorted(a)
f = 0
suum = 0
for i in range(n):
	if f < m or a[i][0] < 0:
		suum += a[i][1]
	else:
		break
	f += 1
for i in range(f, n):
	suum += a[i][1] - a[i][0]
print(suum)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = [x - y for (x, y) in zip(a, b)]
index = sorted(list(range(len(diff))), key=lambda x: diff[x])
cheat = len([x for x in diff if x < 0])
k = max(k, cheat)
bnow = index[:k]
blater = index[k:]
bnow = [a[x] for x in bnow]
blater = [b[x] for x in blater]
print(sum(bnow) + sum(blater))


(n, k) = map(int, input().split())
money = 0
bought = 0
d = []
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
for i in range(n):
	loss = c1[i] - c2[i]
	if loss <= 0:
		money += c1[i]
		bought += 1
	else:
		d.append([loss, c1[i], c2[i]])
d.sort()
for i in range(max(k - bought, 0)):
	money += d[i][1]
for i in range(max(k - bought, 0), len(d)):
	money += d[i][2]
print(money)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [[b[i] - a[i], i] for i in range(n)]
c.sort()
c = c[::-1]
ans = 0
for i in range(k):
	ans += a[c[i][1]]
i = k
while i < n and c[i][0] > 0:
	ans += a[c[i][1]]
	i += 1
while i < n:
	ans += b[c[i][1]]
	i += 1
print(ans)


a = [int(k) for k in input().split()]
b = [int(k) for k in input().split()]
c = [int(k) for k in input().split()]
d = [b[k] - c[k] for k in range(a[0])]
d.sort()
e = 0
while e < a[0] and d[e] < 0:
	e += 1
if e > a[1]:
	print(sum(d[0:e]) + sum(c))
else:
	print(sum(d[0:a[1]]) + sum(c))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
for i in range(n):
	c[i] = a[i] - b[i]
c.sort()
z = 0
for i in range(k):
	z += c[i]
x = 0
for i in range(n):
	x += b[i]
if k != n:
	if c[k] > 0:
		print(x + z)
	else:
		z = 0
		i = 0
		while i < n and c[i] < 0:
			z += c[i]
			i += 1
		print(x + z)
else:
	print(x + z)


(n, x) = list(map(int, input().split()))
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
opt_paid = 0
for i in range(n):
	opt_paid += min(list1[i], list2[i])
diff = []
for i in range(n):
	diff.append(list1[i] - list2[i])
diff.sort()
for j in range(x):
	if diff[j] > 0:
		opt_paid += diff[j]
print(opt_paid)


def sol(n, k, a, b):
	diff = [(a[i] - b[i], i) for i in range(n)]
	diff.sort()
	tot = 0
	for i in range(k):
		tot += a[diff[i][1]]
	for i in range(k, n):
		tot += min(a[diff[i][1]], b[diff[i][1]])
	return tot
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(sol(n, k, a, b))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
ans = sum(a)
dif = [0] * n
for i in range(len(a)):
	dif[i] = b[i] - a[i]
dif = sorted(dif)
for i in range(len(dif)):
	if c == n - k:
		break
	if dif[i] < 0:
		ans += dif[i]
		c += 1
	if dif[i] >= 0:
		break
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = [0] * n
ans = 0
for i in range(n):
	ans += b[i]
	arr[i] = b[i] - a[i]
arr.sort(reverse=True)
sums = 0
for i in range(n):
	if arr[i] < 0 and i >= k:
		break
	sums += arr[i]
print(ans - sums)


(a, b) = map(int, input().split())
z = []
for (i, j) in zip(map(int, input().split()), map(int, input().split())):
	z += [[i - j, i, j]]
z.sort()
s = 0
for i in range(a):
	if b:
		s += z[i][1]
		b -= 1
	elif z[i][0] < 0:
		s += z[i][1]
	else:
		s += z[i][2]
print(s)


def solve(l):
	for i in range(5):
		if abs(l[i] & 1):
			return -1
	ans = 0
	for i in range(5):
		if l[i] > 0:
			ans += l[i] // 2
	return ans
(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = []
d = [0] * n
for i in range(n):
	c.append([a[i] - b[i], i])
ans = 0
c.sort()
for i in range(k):
	ans += a[c[i][1]]
	d[c[i][1]] = 1
for i in range(n):
	if d[i] == 0:
		ans += min(a[i], b[i])
print(ans)


import heapq
(n, k) = map(int, input().split())
first = list(map(int, input().split()))
second = list(map(int, input().split()))
x = 0
cost = 0
for i in range(n):
	if first[i] < second[i]:
		cost += first[i]
		x += 1
if k <= x:
	for i in range(n):
		if first[i] >= second[i]:
			cost += second[i]
else:
	heapsize = k - x
	hp = []
	j = 0
	first_heapify = True
	for i in range(n):
		if first[i] >= second[i]:
			if j < heapsize:
				heapq.heappush(hp, (second[i] - first[i], first[i], i))
				j += 1
			else:
				if first_heapify:
					heapq.heapify(hp)
					first_heapify = False
				mx = -hp[0][0]
				if first[i] - second[i] < mx:
					heapq.heappop(hp)
					heapq.heappush(hp, (second[i] - first[i], first[i], i))
	picked_els = set()
	for el in hp:
		cost += el[1]
		picked_els.add(el[2])
	for i in range(n):
		if first[i] >= second[i] and i not in picked_els:
			cost += second[i]
print(cost)


from math import *
from collections import *
from random import *
from bisect import *
import sys
input = sys.stdin.readline
t = 1
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	r = []
	for i in range(n):
		r.append([a[i] - b[i], i])
	r.sort()
	pos = 0
	for i in r:
		if i[0] <= 0:
			pos += 1
		else:
			break
	re = 0
	for i in range(max(k, pos)):
		re += a[r[i][1]]
	for i in range(max(pos, k), n):
		re += b[r[i][1]]
	print(re)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
wynik = 0
lista = []
for x in range(n):
	lista.append(a[x] - b[x])
	wynik = wynik + b[x]
lista.sort()
for x in range(len(lista)):
	if x < k or lista[x] < 0:
		wynik = wynik + lista[x]
print(wynik)


(n, k) = map(int, input().strip().split(' '))
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
lista = []
for i in range(n):
	aux = a[i] - b[i]
	tupla = (aux, a[i], b[i])
	lista.append(tupla)
lista.sort(key=lambda tup: tup[0])
suma = 0
aux = 0
for tup in lista:
	if k > 0:
		suma += tup[1]
		k -= 1
	else:
		aux += min([tup[1], tup[2]])
		suma += min([tup[1], tup[2]])
print(suma)


from operator import itemgetter

def main():
	(num_item, min_buy) = [int(x) for x in input().split()]
	first_week = [int(x) for x in input().split()]
	second_week = [int(x) for x in input().split()]
	diff = [(first_week[x] - second_week[x], x) for x in range(len(first_week))]
	diff = sorted(diff, key=itemgetter(0))
	sum = 0
	for i in range(min_buy):
		sum += first_week[diff[i][1]]
	for i in range(min_buy, len(first_week)):
		if diff[i][0] <= 0:
			sum += first_week[diff[i][1]]
		else:
			sum += second_week[diff[i][1]]
	print(sum)
main()


(n, k) = list(map(int, input().split()))
discount = list(map(int, input().split()))
nodiscount = list(map(int, input().split()))
count = 0
answer = 0
div = []
for i in range(n):
	div.append([discount[i] - nodiscount[i], discount[i], nodiscount[i]])
for key in sorted(div):
	count += 1
	if count <= k:
		answer += key[1]
	elif count > k:
		answer += min(key[2], key[1])
print(answer)


def findLargest(aList):
	return max(aList)
	pass
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dif = []
for x in range(0, n):
	dif.append(a[x] - b[x])
dif.sort()
thisWeekCount = 0
ans = sum(b)
while thisWeekCount < k or dif[thisWeekCount] < 0:
	ans += dif[thisWeekCount]
	thisWeekCount += 1
	if thisWeekCount == len(dif):
		break
print(ans)


import sys
from itertools import accumulate

def debug(x, table):
	for (name, val) in table.items():
		if x is val:
			print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
			return None

def solve():
	(n, k) = map(int, input().split())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	dif = [a - b for (a, b) in zip(A, B)]
	dif.sort()
	dc = sum(dif[:k])
	for i in range(k, n):
		if dif[i] < 0:
			dc += dif[i]
		else:
			break
	ans = sum(B) + dc
	print(ans)
solve()


(n, k) = map(int, input().split())
old = list(map(int, input().split()))
new = list(map(int, input().split()))
diff = []
for i in range(n):
	diff.append([old[i] - new[i], old[i], new[i], i])
diff.sort()
c = 0
visited = [0] * n
for i in range(k):
	c += diff[i][1]
	visited[diff[i][3]] = 1
for i in range(n):
	if visited[i] == 0:
		c += min(old[i], new[i])
print(c)


[n, k] = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [(a[i] - b[i], a[i], b[i]) for i in range(n)]
c = sorted(c)
s = 0
for i in range(k):
	s += c[i][1]
j = k
while j < n:
	if c[j][0] < 0:
		s += c[j][1]
	else:
		s += c[j][2]
	j += 1
print(s)


(n, k) = [int(x) for x in input().strip().split(' ', 1)]
a = [int(x) for x in input().strip().split(' ')]
b = [int(x) for x in input().strip().split(' ')]
c = [(xb - xa, xa, xb) for (xa, xb) in zip(a, b)]
c.sort(key=lambda x: x[0], reverse=True)
cnt = sum([cx[1] for cx in c[:k]])
while k < n and c[k][0] >= 0:
	cnt += c[k][1]
	k = k + 1
if k < n:
	cnt += sum((cx[2] for cx in c[k:]))
print(cnt)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [(a[i] - b[i], a[i], b[i]) for i in range(n)]
x.sort()
s = x[0:k]
t = []
for i in range(k, n):
	if x[i][0] > 0:
		t.append(x[i])
	else:
		s.append(x[i])
ans = 0
for i in s:
	ans += i[1]
for i in t:
	ans += i[2]
print(ans)


def Pupils_redistribution():
	n = int(input())
	g1 = input().split()
	g1d = [0] * 5
	g2 = input().split()
	g2d = [0] * 5
	for i in g1:
		g1d[int(i) - 1] += 1
	for i in g2:
		g2d[int(i) - 1] += 1
	nd = [0] * 5
	for i in range(len(g1d)):
		a = g1d[i] - g2d[i]
		if a % 2 == 0:
			nd[i] = a / 2
		else:
			print('-1')
			break
	else:
		if sum(nd) == 0:
			sums = 0
			for i in nd:
				if i > 0:
					sums += i
			print(int(sums))
		else:
			print('-1')

def Weird_rounding():
	r = input().split()
	n = r[0]
	lenn = len(n)
	n2 = n
	k = int(r[1])
	ten = 10 ** k
	count = 0
	for i in range(lenn):
		if int(n2) % ten == 0:
			break
		if int(n2[lenn - i - 1]) != 0:
			count += 1
			n2 = n2[:lenn - i - 1] + n2[lenn - i:]
	if int(n2) == 0 and len(n2) > 1:
		print(count + len(n2) - 1)
	else:
		print(count)

def Dishonest_sellers():
	a = input().split()
	n = int(a[0])
	k = int(a[1])
	a = input().split()
	b = input().split()
	diff = [0] * n
	for i in range(n):
		diff[i] = (int(b[i]) - int(a[i]), i)
	diff = sorted(diff, reverse=True)
	count = 0
	for i in range(n):
		if i < k:
			count += int(a[diff[i][1]])
		elif diff[i][0] >= 0:
			count += int(a[diff[i][1]])
		else:
			count += int(b[diff[i][1]])
	print(count)
Dishonest_sellers()


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
data = sorted(list(zip(a, b)), key=lambda x: x[1] - x[0])
ans = sum(map(lambda x: min(x[0], x[1]), data[:len(data) - k]))
if k:
	ans += sum(map(lambda x: x[0], data[-k:]))
print(ans)


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
ans = 0
cnt = 0
bought = set()
for i in range(n):
	if a[i] <= b[i]:
		ans += a[i]
		cnt += 1
		bought.add(i)
c = {i: a[i] - b[i] for i in range(n) if i not in bought}
c = sorted(((i, diff) for (i, diff) in c.items()), key=lambda x: x[1])
for (i, diff) in c:
	if cnt < k:
		cnt += 1
		ans += a[i]
	else:
		ans += b[i]
print(ans)


(n, k) = map(int, input().split(' '))
lst1 = list(map(int, input().split(' ')))
lst2 = list(map(int, input().split(' ')))
d = sorted((a - b for (a, b) in zip(lst2, lst1) if a - b < 0))
print('{}'.format(sum(lst1) + sum(d[:n - k])))


class toode:

	def __init__(self, a, b):
		self.hind1 = a
		self.hind2 = b

	def __str__(self):
		return str(self.hind1) + ' ' + str(self.hind2)

def Compare(a, b):
	return a.hind1 - a.hind2 - (b.hind1 - b.hind2)

def cmp_to_key(mycmp):

	class K(object):

		def __init__(self, obj, *args):
			self.obj = obj

		def __lt__(self, other):
			return mycmp(self.obj, other.obj) < 0

		def __gt__(self, other):
			return mycmp(self.obj, other.obj) > 0

		def __eq__(self, other):
			return mycmp(self.obj, other.obj) == 0

		def __le__(self, other):
			return mycmp(self.obj, other.obj) <= 0

		def __ge__(self, other):
			return mycmp(self.obj, other.obj) >= 0

		def __ne__(self, other):
			return mycmp(self.obj, other.obj) != 0
	return K
(n, k) = map(int, input().split())
(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
tooted = sorted([toode(a[i], b[i]) for i in range(n)], key=cmp_to_key(Compare))
ans = 0
for x in range(k):
	ans += tooted[x].hind1
for x in range(k, n):
	ans += min(tooted[x].hind1, tooted[x].hind2)
print(ans)


int_inp = lambda : int(input())
strng = lambda : input().strip()
strl = lambda : list(input().strip())
mul = lambda : map(int, input().split())
mulf = lambda : map(float, input().split())
seq = lambda : list(map(int, input().split()))
import math
from collections import Counter, defaultdict
(n, m) = mul()
a = seq()
b = seq()
k = 0
p = []
for (i, j) in zip(a, b):
	p.append([i - j, k])
	k += 1
p.sort()
last = -1
k = 0
for i in p:
	if i[0] > 0 and last <= 0:
		break
	k += 1
if k > m:
	m = k
ans = 0
for i in range(m):
	ans += a[p[i][1]]
for i in range(m, n):
	ans += b[p[i][1]]
print(ans)


import sys

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

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

def SieveOfEratosthenes(n):
	cnt = 0
	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
	for p in range(2, n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

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

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

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

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

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
(n, k) = nninp()
a = llinp()
b = llinp()
diff = []
s = 0
for i in range(n):
	diff.append([a[i] - b[i], i])
diff.sort()
for c in diff:
	if k > 0 or c[0] <= 0:
		s = s + a[c[1]]
		k = k - 1
	else:
		s = s + b[c[1]]
p(s)


from sys import stdin, stdout

def get_prices():
	prices = []
	lst1 = [int(x) for x in stdin.readline().rstrip('\r\n').split()]
	lst2 = [int(x) for x in stdin.readline().rstrip('\r\n').split()]
	for i in range(n):
		prices.append((lst1[i] - lst2[i], lst1[i], lst2[i]))
	return sorted(prices)

def solve(n, k, prices):
	amount = 0
	remain = 0
	for price in prices:
		if price[0] < 0:
			amount += price[1]
		elif k - remain > 0:
			amount += price[1]
		else:
			amount += price[2]
		remain += 1
	return amount
(n, k) = map(int, input().split())
prices = get_prices()
solution = solve(n, k, prices)
print(solution)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted(zip(a, b), key=lambda x: x[0] - x[1])
res = 0
for (idx, value) in enumerate(c):
	if value[0] - value[1] <= 0:
		res += value[0]
	elif idx >= k:
		res += value[1]
	else:
		res += value[0]
print(res)


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


import sys
import math
from collections import defaultdict

def solve(test):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [(a[i] - b[i], a[i], b[i]) for i in range(n)]
	c.sort(key=lambda x: x[0])
	ans = 0
	for i in range(n):
		(val, dis, act) = c[i]
		if val <= 0:
			ans += dis
			k -= 1
		elif k > 0:
			ans += dis
			k -= 1
		else:
			ans += act
	print(ans)
test_cases = 1
for t in range(1, test_cases + 1):
	solve(t)


cnt = lambda s, x: s.count(x)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
dgl = lambda : list(map(int, input()))
il = lambda : list(map(int, input().split()))
(n, k) = f()
bd = il()
ad = il()
sm = 0
dif = []
for i in range(n):
	dif.append([bd[i] - ad[i], i])
dif.sort()
for i in range(n):
	if k > 0:
		sm += bd[dif[i][1]]
		k -= 1
	elif dif[i][0] >= 0:
		sm += ad[dif[i][1]]
	else:
		sm += bd[dif[i][1]]
print(sm)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
price = [[] for i in range(n)]
for i in range(n):
	price[i].append(a[i])
	price[i].append(b[i])
	price[i].append(a[i] - b[i])
price.sort(key=lambda x: x[2])
min = 0
for i in range(k):
	min += price[i][0]
while k < n and price[k][2] < 0:
	min += price[k][0]
	k += 1
while k < n:
	min += price[k][1]
	k += 1
print(min)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = [(i, ii) for (i, ii) in zip(a, b)]
l.sort(reverse=True, key=lambda x: x[1] - x[0])
ans = 0
for (ii, i) in enumerate(l):
	if ii < m:
		ans += i[0]
	else:
		ans += min(i[1], i[0])
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
d = list(map(int, input().split()))
dd = []
s = sum(l)
for i in range(n):
	x = d[i] - l[i]
	dd.append(x)
dd.sort(reverse=True)
for i in range(k, n):
	if dd[i] < 0:
		s = s + dd[i]
print(s)


def main():
	(n, k) = tuple(map(int, input().split(' ')))
	list_curr = list(map(int, input().split(' ')))
	list_next = list(map(int, input().split(' ')))
	list_zip = list(zip(list_curr, list_next))
	list_zip.sort(key=lambda x: x[0] - x[1])
	price = 0
	for i in range(n):
		if i < k:
			price += list_zip[i][0]
		else:
			price += min(list_zip[i][0], list_zip[i][1])
	print(price)
main()


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


(n, k) = map(int, input().split())
now = list(map(int, input().split()))
aftr = list(map(int, input().split()))
ans = sum(aftr)
for i in range(n):
	now[i] -= aftr[i]
now.sort()
for i in range(n):
	if i < k or now[i] < 0:
		ans += now[i]
	else:
		break
print(ans)


n = list(map(int, input().split()))
l = list(map(int, input().split()))
ll = list(map(int, input().split()))
z = zip(l, ll)
t = [p[0] - p[1] for p in z]
temp = zip(t, l, ll)
temp = sorted(temp)
count = 0
ans = 0
for (a, b, c) in temp:
	if count < n[1] or a < 0:
		ans += b
		count += 1
	else:
		ans += c
print(ans)


import sys
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dif = []
for i in range(n):
	dif.append((a[i] - b[i], a[i], b[i]))
dif.sort()
ans = 0
for i in range(0, k):
	ans += dif[i][1]
for i in range(k, n):
	ans += min(dif[i][1], dif[i][2])
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dif = []
for i in range(n):
	dif.append((a[i] - b[i], i))
dif.sort()
s = 0
for i in range(k):
	s += a[dif[i][1]]
	a[dif[i][1]] = b[dif[i][1]] = 0
for i in range(len(a)):
	s += min(a[i], b[i])
print(s)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
cnt = 0
for i in range(len(a)):
	if a[i] <= b[i]:
		cnt += 1
		ans += a[i]
		a[i] = 0
		b[i] = 0
new = []
p = [0, 0, 0]
for i in range(len(a)):
	if a[i] != 0:
		p[0] = a[i] - b[i]
		p[1] = a[i]
		p[2] = b[i]
		new.append(tuple(p))
new.sort()
for i in range(len(new)):
	if cnt < k:
		ans += new[i][1]
		cnt += 1
	else:
		ans += new[i][2]
print(ans)


n = list(map(int, input().split()))
l = list(map(int, input().split()))
t = list(map(int, input().split()))
d = sorted([l[i] - t[i] for i in range(len(l))])
for i in range(len(d)):
	n[0] = n[0] + min(t[i], l[i])
for j in range(n[1]):
	n[0] = n[0] + max(d[j], 0)
print(n[0] - len(d))


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
for i in range(n):
	C.append((A[i] - B[i], i))
C.sort()
ans = 0
for i in range(k):
	ans += A[C[i][1]]
g = n
for i in range(k, n):
	if C[i][0] <= 0:
		ans += A[C[i][1]]
	else:
		g = i
		break
for j in range(g, n):
	ans += B[C[j][1]]
print(ans)


def f():
	i1 = input().strip().split()
	(n, k) = (int(i1[0]), int(i1[1]))
	i2 = input().strip().split()
	i3 = input().strip().split()
	b = [int(x) for x in i2]
	a = [int(x) for x in i3]
	p = [a[i] - b[i] for i in range(n)]
	p = sorted(p)
	d = 0
	sum = 0
	for i in b:
		sum += i
	for i in reversed(p):
		if i < 0:
			break
		d += 1
	if d >= k:
		for i in p[0:n - d]:
			sum += i
		print(sum)
		return
	for i in p[0:n - k]:
		sum += i
	print(sum)
f()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = sorted([(a[i] - b[i], i) for i in range(n)])
k = max(k, len([d for d in diff if d[0] < 0]))
ans = sum([a[i] for (d, i) in diff[:k]] + [b[i] for (d, i) in diff[k:]])
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [(a[i], b[i]) for i in range(n)]
c.sort(key=lambda val: val[0] - val[1])
res = 0
for i in c:
	if k > 0 or i[0] < i[1]:
		res += i[0]
		k -= 1
	else:
		res += i[1]
print(res)


(n, m) = input().split()
(n, m) = [int(n), int(m)]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
money = 0
diff = []
for i in range(n):
	diff.append((a[i] - b[i], i))
diff.sort()
for i in range(m):
	t = diff[i]
	money += a[t[1]]
for i in range(m, n):
	t = diff[i]
	if t[0] < 0:
		money += a[t[1]]
	else:
		money += b[t[1]]
print(money)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
vis = [0] * n
(tot, buy) = (0, 0)
for i in range(n):
	if arr[i] <= brr[i]:
		buy += 1
		tot += arr[i]
		vis[i] = 1
if buy >= k:
	for i in range(n):
		if vis[i] == 0:
			tot += brr[i]
	print(tot)
else:
	crr = []
	for i in range(n):
		if vis[i] == 0:
			crr.append(i)
	crr.sort(key=lambda x: arr[x] - brr[x])
	for i in range(k - buy):
		tot += arr[crr[i]]
	for i in range(k - buy, len(crr)):
		tot += brr[crr[i]]
	print(tot)


(n, k) = map(int, input().split())
now = [int(inp) for inp in input().split()]
after = [int(inp) for inp in input().split()]
diff = []
for i in range(n):
	diff.append([after[i] - now[i], i])
diff.sort(key=lambda x: x[0])
ans = 0
for i in range(n - 1, -1, -1):
	index = diff[i][1]
	if k > 0 or diff[i][0] >= 0:
		ans += now[index]
		k -= 1
	else:
		ans += after[index]
print(ans)


dr = []
m = []
s = 0
c = -1
(x, y) = map(int, input().split())
fd = list(map(int, input().split()))
sd = list(map(int, input().split()))
for i in range(x):
	dr.append(fd[i] - sd[i])
	m.append(min(fd[i], sd[i]))
dr.sort()
s = sum(m)
for i in range(x):
	if dr[i] <= 0:
		c = i
	else:
		break
if c + 1 >= y:
	print(s)
else:
	for i in range(c + 1, y):
		s += dr[i]
	print(s)


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


from operator import itemgetter
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ar = []
for i in range(n):
	ar.append([a[i], b[i], a[i] - b[i]])
ar = sorted(ar, key=itemgetter(2))
co = 0
for i in range(k):
	co += ar[i][0]
for i in range(k, n):
	if ar[i][2] < 0:
		co += ar[i][0]
	else:
		co += ar[i][1]
print(co)


(n, k) = map(int, input().split())
op = [int(i) for i in input().split()]
np = [int(i) for i in input().split()]
diff = [(i, op[i] - np[i]) for i in range(len(op))]
diff_sort = sorted(diff, key=lambda x: x[1])
i = 0
tc = 0
for i in range(len(diff_sort)):
	if k > 0 or diff_sort[i][1] < 0:
		tc += op[diff_sort[i][0]]
		k -= 1
	else:
		tc += np[diff_sort[i][0]]
print(tc)


def main():
	(n, k) = tuple(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ind = [x for x in range(n)]
	ind = sorted(ind, key=lambda index: a[index] - b[index])
	res = 0
	for i in range(n):
		if i < k:
			res += a[ind[i]]
		elif a[ind[i]] <= b[ind[i]]:
			res += a[ind[i]]
		else:
			res += b[ind[i]]
	print(res)
main()


lineOne = input()
dataOne = lineOne.split()
n = int(dataOne[0])
rightNow = int(dataOne[1])
lTwo = input()
discount = [int(i) for i in lTwo.split()]
lThree = input()
after = [int(i) for i in lThree.split()]
diff = []
ans = 0
k = 0
for i in range(n):
	if discount[i] <= after[i]:
		ans += discount[i]
		k += 1
	else:
		diff.append(after[i] - discount[i])
		ans += after[i]
diff.sort()
while k < rightNow:
	ans -= diff.pop()
	k += 1
print(ans)


from sys import maxsize, stdout, stdin, stderr
tup = lambda : map(int, stdin.readline().split())
I = lambda : int(stdin.readline())
lint = lambda : [int(x) for x in stdin.readline().split()]
S = lambda : stdin.readline().replace('\n', '').strip()

def debug(*args, c=6):
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=stderr)
stpr = lambda x: stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
from collections import defaultdict, Counter
from math import gcd
from bisect import bisect_left
from math import floor, ceil
(n, k) = tup()
(l1, l2, t2) = (lint(), lint(), k)
d = [(l1[i], l2[i]) for i in range(n)]
f = sorted(d, key=lambda x: x[0] - x[1])
(se, s) = ([], 0)
for i in range(n):
	if i < k:
		s += f[i][0]
	else:
		s += min(f[i][0], f[i][1])
print(s)


def key_my(idx):
	return -idx[0]
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans_win = []
ans_l = []
for i in range(n):
	if b[i] < a[i]:
		ans_l.append([b[i] - a[i], i])
	else:
		ans_win.append([b[i] - a[i], i])
cur = 0
use = [0] * n
if k <= len(ans_win):
	for i in range(len(ans_win)):
		cur += a[ans_win[i][1]]
		use[ans_win[i][1]] = 1
	for i in range(n):
		if not use[i]:
			cur += b[i]
	print(cur)
else:
	ans_win.sort(key=key_my)
	ans_l.sort(key=key_my)
	for i in range(len(ans_win)):
		cur += a[ans_win[i][1]]
		use[ans_win[i][1]] = 1
	for i in range(k - len(ans_win)):
		cur += a[ans_l[i][1]]
		use[ans_l[i][1]] = 1
	for i in range(n):
		if not use[i]:
			cur += b[i]
	print(cur)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 5
T = 1
for _ in range(T):
	(n, k) = list(map(int, stdin.readline().rstrip().split()))
	a = list(map(int, stdin.readline().rstrip().split()))
	b = list(map(int, stdin.readline().rstrip().split()))
	ans = 0
	for i in range(n):
		if a[i] <= b[i]:
			ans += a[i]
			k -= 1
		else:
			ans += b[i]
	d = [0] * n
	for i in range(n):
		d[i] = a[i] - b[i]
	d.sort()
	for i in range(n):
		if d[i] > 0:
			break
	while k > 0:
		ans += d[i]
		i += 1
		k -= 1
	print(ans)


(n, m) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
L = []
k = 0
for i in range(n):
	L.append([l1[i] - l2[i], l1[i], l2[i]])
L = sorted(L)
for i in range(n):
	if L[i][0] <= 0:
		k = k + L[i][1]
	elif m <= 0:
		k = k + L[i][2]
	else:
		k = k + L[i][1]
	m = m - 1
print(k)


(n, k) = [int(i) for i in input().split()]
l1 = [int(i) for i in input().split()]
l2 = [int(i) for i in input().split()]
l3 = []
for i in range(n):
	l3.append([l1[i] - l2[i], i])
l3 = sorted(l3, key=lambda l: l[0], reverse=False)
sum = 0
for i in range(k):
	sum = sum + l1[l3[i][1]]
for i in range(k, n):
	if l3[i][0] < 0:
		sum = sum + l1[l3[i][1]]
	else:
		sum = sum + l2[l3[i][1]]
print(sum)


(n, k) = list(map(int, input().split()))
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = [(l1[i], l2[i]) for i in range(n)]
l3.sort(key=lambda x: x[0] - x[1])
ans = 0
for i in range(k):
	ans += l3[i][0]
for i in range(k, n):
	if l3[i][0] > l3[i][1]:
		ans += l3[i][1]
	else:
		ans += l3[i][0]
print(ans)


[n, k] = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
al = list(zip(a, b))
al.sort(key=lambda x: x[0] - x[1])
i = 0
ans = 0
while i < n and (i < k or al[i][1] > al[i][0]):
	ans += al[i][0]
	i += 1
ans += sum(map(lambda x: x[1], al[i:]))
print(ans)


def minCost(arr1, arr2, k):
	n = len(arr1)
	cost = 0
	for i in arr1:
		cost += i
	arr = list()
	for i in range(len(arr1)):
		diff = arr1[i] - arr2[i]
		arr.append(diff)
	arr.sort()
	i = n - 1
	num = n - k
	while i >= 0 and num > 0:
		if arr[i] > 0:
			cost -= arr[i]
			num -= 1
		i -= 1
	return cost
inputArray = input('').strip().split()
n = int(inputArray[0])
k = int(inputArray[1])
arr1 = list()
arr2 = list()
inputArray = input('').strip().split()
for i in inputArray:
	arr1.append(int(i))
inputArray = input('').strip().split()
for i in inputArray:
	arr2.append(int(i))
print(minCost(arr1, arr2, k))


import operator
import operator
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
increaseInPrice = dict()
for i in range(n):
	increaseInPrice[i] = b[i] - a[i]
sortedIncrease = sorted(increaseInPrice.items(), key=operator.itemgetter(1))
i = n - 1
totalCost = 0
while i > -1:
	if k > 0:
		k -= 1
		totalCost += a[sortedIncrease[i][0]]
	else:
		totalCost += min(a[sortedIncrease[i][0]], b[sortedIncrease[i][0]])
	i -= 1
print(totalCost)


def Sort(sub_li):
	return sorted(sub_li, key=lambda x: x[1])
o = input().rstrip().split(' ')
p = input().rstrip().split(' ')
r = input().rstrip().split(' ')
l = []
q = []
w = []
S = []
D = []
for i in range(0, len(p)):
	D = []
	D.append(int(p[i]))
	D.append(int(r[i]) - int(p[i]))
	D.append(int(r[i]))
	l.append(D)
X = Sort(l)
X.reverse()
k = int(o[1])
F = 0
V = -1
for i in range(0, len(X)):
	if X[i][1] >= 0:
		F += X[i][0]
		k -= 1
	elif k <= 0:
		V = i
		break
	else:
		k -= 1
		F += X[i][0]
if V == -1:
	print(F)
else:
	for i in range(V, len(X)):
		F += X[i][2]
	print(F)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
I = sys.stdin.readline

def ii():
	return int(I().strip())

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

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

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def div(n):
	tmp = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			cnt = 0
			while n % i == 0:
				n = n // i
				cnt += 1
			tmp.append((i, cnt))
	if n > 1:
		tmp.append((n, 1))
	return tmp

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

def s(b):
	cnt = 0
	while b > 0:
		tmp = b % 10
		cnt += tmp
		b = b // 10
	return cnt

def main():
	(n, k) = mi()
	a = li()
	b = li()
	tmp = [(a[i], b[i]) for i in range(n)]
	my_arr = sorted(tmp, key=lambda x: x[0] - x[1])
	cnt = 0
	i = 0
	cost = 0
	while cnt < n and (cnt < k or my_arr[cnt][0] - my_arr[cnt][1] < 0):
		cost += my_arr[cnt][0]
		cnt += 1
	while cnt < n:
		cost += my_arr[cnt][1]
		cnt += 1
	print(cost)
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

class CItem:
	diff = 0
	a = 0
	b = 0
Items = []
for i in range(0, n):
	Item = CItem()
	Item.a = a[i]
	Item.b = b[i]
	Item.diff = b[i] - a[i]
	Items.append(Item)
Items.sort(key=lambda x: x.diff, reverse=True)
money = 0
for i in range(0, k):
	money += Items[i].a
for i in range(k, n):
	money += min(Items[i].b, Items[i].a)
print(money)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d1 = 0
d2 = []
for i in range(n):
	if a[i] <= b[i]:
		d1 += a[i]
		k -= 1
	else:
		d2.append((a[i] - b[i], i))
d2 = sorted(d2)
for i in range(len(d2)):
	if k > 0:
		d1 += a[d2[i][1]]
		k -= 1
	else:
		d1 += b[d2[i][1]]
print(d1)


(n, k) = input().split()
(n, k) = (int(n), int(k))
li1 = list(map(int, input().split()))
li2 = list(map(int, input().split()))
cnt = 0
total = 0
li = []
for x in range(n):
	if li1[x] <= li2[x]:
		total += li1[x]
		cnt += 1
	else:
		li.append((li1[x] - li2[x], li2[x]))
li.sort()
li.reverse()
if cnt < k:
	for x in range(k - cnt):
		val = li.pop()
		total += val[1] + val[0]
if li:
	for x in li:
		total += x[1]
print(total)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = sum(B)
for i in range(N):
	A[i] -= B[i]
A.sort()
for i in range(N):
	if i < K or A[i] < 0:
		ans += A[i]
	else:
		break
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list()
for i in range(n):
	c.append((i, b[i] - a[i]))
c.sort(key=lambda x: x[1])
c = c[::-1]
r = 0
for i in range(n):
	if i < k or c[i][1] > 0:
		r += a[c[i][0]]
	else:
		r += b[c[i][0]]
print(r)


(n, k) = map(int, input().split())
before = [int(i) for i in input().split()]
after = [int(i) for i in input().split()]
difference = sorted([[after[i] - before[i], i] for i in range(n)])
j = 0
for i in range(n):
	if difference[i][0] > 0:
		j = n - i
		break
final_sum = 0
for i in range(max(k, j)):
	final_sum += before[difference[-i - 1][1]]
for i in range(n - max(k, j)):
	final_sum += after[difference[i][1]]
print(final_sum)


import sys
(n, k) = map(int, sys.stdin.readline().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0 for i in range(len(a))]
count = sum(b)
for i in range(len(a)):
	c[i] = b[i] - a[i]
c.sort()
c.reverse()
for i in range(len(a)):
	if i < k:
		count = count - c[i]
	elif c[i] > 0:
		count = count - c[i]
	else:
		break
print(count)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sum(b)
for i in range(n):
	a[i] -= b[i]
a = sorted(a)
for i in range(n):
	if i < k or a[i] < 0:
		c += a[i]
print(c)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = sum(b)
for i in range(0, len(a)):
	a[i] -= b[i]
a.sort()
for i in range(0, len(a)):
	if i < k or a[i] < 0:
		ans += a[i]
	else:
		break
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum_max = sum(b)
c = list(map(lambda x, y: x - y, a, b))
c.sort()
for i in range(n):
	if i < k or c[i] < 0:
		sum_max += c[i]
	else:
		break
print(sum_max)


def ri():
	return map(int, input().split())
(n, k) = ri()
a = list(ri())
b = list(ri())
c = [a[i] - b[i] for i in range(n)]
d = list(zip(c, a, b))
d.sort()
ans = 0
for i in range(k):
	ans += d[i][1]
for i in range(k, n):
	ans += min(d[i][1], d[i][2])
print(ans)


import sys

def input():
	return sys.stdin.readline()
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
prices_n_sales = sorted(list(zip(b, (i - j for (i, j) in zip(a, b)))), key=lambda x: x[1])
total = sum((ps[0] + ps[1] for ps in prices_n_sales[:k]))
i = k
if i == n:
	print(total)
	return
while prices_n_sales[i][1] < 0:
	total += prices_n_sales[i][0] + prices_n_sales[i][1]
	i += 1
	if i >= n:
		break
print(total + sum((ps[0] for ps in prices_n_sales[i:])))


from sys import stdin

def get_ints():
	return list(map(int, stdin.readline().strip().split()))
(n, k) = get_ints()
a = get_ints()
b = get_ints()
c = [a[i] - b[i] for i in range(n)]
c1 = c.copy()
(c, a) = zip(*sorted(zip(c, a)))
(c1, b) = zip(*sorted(zip(c1, b)))
num = 0
s = 0
for i in range(n):
	if c[i] < 0:
		num += 1
		s += a[i]
	elif num < k:
		num += 1
		s += a[i]
	else:
		num += 1
		s += b[i]
print(s)


def main():
	(n, k) = map(int, input().split())
	prices = list(map(int, input().split()))
	price_in_wk = list(map(int, input().split()))
	profits = [(prices[i] - price_in_wk[i], i) for i in range(len(prices))]
	profits.sort()
	cost = 0
	count = 0
	i = 0
	while i < len(profits):
		if profits[i][0] < 0:
			count += 1
			cost += prices[profits[i][1]]
		elif count >= k:
			break
		else:
			cost += prices[profits[i][1]]
			count += 1
		i += 1
	for i in range(n - count):
		cost += price_in_wk[profits[count + i][1]]
	print(cost)
main()


(n, k) = map(int, input().split())
b = list(map(int, input().split()))
a = list(map(int, input().split()))
x = []
for i in range(n):
	x += [[b[i] - a[i], i]]
x.sort()
used = set()
total = 0
for i in range(k):
	total += b[x[i][1]]
	used.add(x[i][1])
for i in range(n):
	if i not in used:
		total += min(a[i], b[i])
print(total)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ls = []
for i in range(n):
	ls.append([a[i] - b[i], i])
ls.sort()
cnt = 0
i = 0
while i < k:
	cnt += a[ls[i][1]]
	i += 1
for i in range(k, n):
	if ls[i][0] <= 0:
		cnt += a[ls[i][1]]
	else:
		cnt += b[ls[i][1]]
print(cnt)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
d = [[a[i], b[i], a[i] - b[i]] for i in range(n)]
del a, b
d = sorted(d, key=lambda x: x[2])
s = 0
for i in range(n):
	if k > 0:
		s += d[i][0]
		k -= 1
	else:
		s += min(d[i][0], d[i][1])
print(s)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
V = []
for i in range(n):
	V.append([A[i] - B[i], i])
V.sort()
s = 0
for i in range(n):
	if i + 1 <= k or V[i][0] < 0:
		s += A[V[i][1]]
	else:
		s += B[V[i][1]]
print(s)


(a, b) = map(int, input().split())
p1 = list(map(int, input().split()))
p2 = list(map(int, input().split()))
3
delta = [(p1[i] - p2[i], i) for i in range(a)]
delta.sort()
ll = len([i for i in delta if i[0] <= 0])
b = max(ll, b)
l1 = [delta[i][1] for i in range(b)]
l2 = [delta[i][1] for i in range(b, a)]
m = [p1[i] for i in l1]
n = [p2[i] for i in l2]
print(sum(m + n))


(n, k) = map(int, input().split())
pn = list(map(int, input().split()))
pl = list(map(int, input().split()))
pri = []
for i in range(n):
	pri.append([pn[i] - pl[i], i])
pri = sorted(pri, key=lambda t: t[0])
c = 0
t = 0
for i in range(n):
	if t < k:
		c += pn[pri[i][1]]
		t += 1
	elif pri[i][0] < 0:
		c += pn[pri[i][1]]
	else:
		c += pl[pri[i][1]]
print(c)


from operator import itemgetter
c = 1
cases = 1
while c <= cases:
	[n, k] = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ab = []
	ba = []
	for i in range(0, n):
		if a[i] <= b[i]:
			ab.append((abs(a[i] - b[i]), i))
		else:
			ba.append((abs(a[i] - b[i]), i))
	ab.sort(key=itemgetter(0), reverse=True)
	ba.sort()
	cnt = 0
	ans = 0
	for (e, i) in ab:
		ans += a[i]
		b[i] = 0
		cnt += 1
	if cnt < k:
		for (e, i) in ba:
			if cnt == k:
				break
			ans += a[i]
			b[i] = 0
			cnt += 1
	print(ans + sum(b))
	c = c + 1


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = list(map(lambda i: (i, b[i] - a[i]), range(n)))
arr = sorted(d, key=lambda x: x[1], reverse=True)
s = 0
for (index, value) in enumerate(arr):
	if index < k:
		s += a[value[0]]
	elif value[1] < 0:
		s += b[value[0]]
	else:
		s += a[value[0]]
print(s)


(n, k) = map(int, input().split())
a = sorted(([a - b, a, b] for (a, b) in zip(map(int, input().split()), map(int, input().split()))))
print(sum((ai[1] if i < k or ai[0] < 0 else ai[2] for (i, ai) in enumerate(a))))


(n, k) = [int(i) for i in input().split(' ')]
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
summ = 0
for i in range(n):
	summ += B[i]
discounts = []
for i in range(n):
	discounts.append(B[i] - A[i])
cnt = 0
discounts.sort()
for i in range(n - 1, -1, -1):
	if discounts[i] >= 0 or cnt < k:
		cnt += 1
		summ -= discounts[i]
print(summ)


def solve(n, toBuy, seq1, seq2):
	zipped = list(zip(seq1, seq2))
	totalAfterPromo = sum(seq2)
	buyBeforePromo = 0
	items = 0
	afterSmall = []
	for (before, after) in zipped:
		if before <= after:
			items += 1
			buyBeforePromo += before
			totalAfterPromo -= after
		else:
			afterSmall.append([before - after, after])
	if items < toBuy:
		afterSmall.sort(key=lambda x: x[0])
		index = 0
		while index < toBuy - items:
			buyBeforePromo += afterSmall[index][1] + afterSmall[index][0]
			totalAfterPromo -= afterSmall[index][1]
			index += 1
	return buyBeforePromo + totalAfterPromo
(n, toBuy) = list(map(int, input().split()))
seq1 = list(map(int, input().split()))
seq2 = list(map(int, input().split()))
print(solve(n, toBuy, seq1, seq2))


(n, k) = [int(x) for x in input().strip().split()]
a = [-int(x) for x in input().strip().split()]
b = [int(x) for x in input().strip().split()]
total = 0
diff = [[sum(x), x] for x in zip(a, b)]
diff.sort(key=lambda x: x[0])
for _ in range(k):
	t = diff.pop()
	total += -t[1][0]
for t in diff:
	if t[0] < 0:
		total += t[1][1]
	else:
		total += -t[1][0]
print(total)


from heapq import *
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
q = []
for i in range(n):
	heappush(q, (a[i] - b[i], a[i], b[i]))
ans = 0
while k > 0:
	ans += heappop(q)[1]
	k -= 1
while len(q) > 0:
	temp = heappop(q)
	ans += min(temp[1], temp[2])
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = []
for i in range(n):
	l.append([a[i] - b[i], a[i], b[i]])
l.sort()
c = s = 0
for i in range(n):
	if c >= m and l[i][0] > 0:
		s += l[i][2]
	else:
		s += l[i][1]
	c += 1
print(s)


import math
import sys
from collections import *
from bisect import bisect_left, bisect_right

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

def cstr():
	return list(map(str, input().split(' ')))

def solve():
	(n, k) = cint()
	l1 = cint()
	l2 = cint()
	lst = []
	ans = 0
	for i in range(n):
		if l1[i] <= l2[i]:
			ans += l1[i]
			k -= 1
		else:
			diff = l1[i] - l2[i]
			lst.append([diff, l2[i]])
	lst.sort()
	for item in lst:
		if k <= 0:
			ans += item[1]
		else:
			ans += item[1] + item[0]
			k -= 1
	print(ans)
t = 1
while t != 0:
	solve()
	t -= 1


(n, k) = map(int, input().split())
arr1 = [int(x) for x in input().split()]
arr2 = [int(x) for x in input().split()]
arr3 = [10001] * n
cnt = 0
tt = 0
for i in range(n):
	if arr1[i] > arr2[i]:
		tt += arr2[i]
		arr3[i] = arr1[i] - arr2[i]
	else:
		tt += arr1[i]
		cnt += 1
if cnt >= k:
	print(tt)
else:
	arr3.sort()
	i = 0
	while cnt < k:
		tt += arr3[i]
		cnt += 1
		i += 1
	print(tt)


from bisect import *
(n, k) = map(int, input().split())
a = map(int, input().split())
b = list(map(int, input().split()))
d = sorted((a - b for (a, b) in zip(a, b)))
print(sum(b) + sum(d[:max(k, bisect(d, 0))]))


(N, K) = input().strip().split()
(N, K) = (int(N), int(K))
discounts = input().strip().split()
normal = input().strip().split()
items = []
for i in range(N):
	a = int(discounts[i])
	b = int(normal[i])
	items.append([a, b, min(a, b), a - b])
money = 0
items = sorted(items, key=lambda k: k[3], reverse=True)
for i in range(K):
	item = items.pop()
	money += item[0]
items = sorted(items, key=lambda k: k[2], reverse=True)
for i in range(N - K):
	item = items.pop()
	money += item[2]
print(money)


(n, k) = map(int, input().split())
AB = [[0 for x in range(3)] for x in range(n)]
A = input().split()
B = input().split()
for index in range(n):
	AB[index][0] = int(A[index])
	AB[index][1] = int(B[index])
	AB[index][2] = AB[index][0] - AB[index][1]
AB = sorted(AB, key=lambda x: x[2])
summer = 0
for index in range(0, k):
	summer += AB[index][0]
for index in range(k, n):
	if AB[index][2] <= 0:
		summer += AB[index][0]
	else:
		summer += AB[index][1]
print(summer)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
d = []
for i in range(n):
	d.append((a[i] - b[i], i, a[i], b[i]))
d.sort()
total = 0
for i in range(n):
	if k > 0 or d[i][0] <= 0:
		total += d[i][2]
		k -= 1
	else:
		total += d[i][3]
print(total)


class Stuff:

	def __init__(self, before, after):
		self._before = before
		self._after = after
		self._discount = self._before - self._after

	@staticmethod
	def discount(someStuff):
		return somestuff.discount()

	def discount(self):
		return self._discount

	def __str__(self):
		return '(' + str(self._before) + ',' + str(self._after) + ')'
(n, k) = [int(i) for i in input().strip().split(' ')]
a = [int(i) for i in input().strip().split(' ')]
b = [int(i) for i in input().strip().split(' ')]
allStuff = [Stuff(a[i], b[i]) for i in range(n)]
allStuff.sort(key=Stuff.discount)
money = 0
for thisStuff in allStuff:
	if k > 0:
		money += thisStuff._before
		k -= 1
	else:
		money += min(thisStuff._before, thisStuff._after)
print(money)


import sys
import re
import math
import itertools
import collections
import bisect
mod = 1000000007
pi = 3.141592653589793
IS = float('inf')
xy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
bs = [(-1, -1), (-1, 1), (1, 1), (1, -1)]

def niten(a, b):
	return abs(a - b) if a >= 0 and b >= 0 else a + abs(b) if a >= 0 else abs(a) + b if b >= 0 else abs(abs(a) - abs(b))

def fib(n):
	return [(seq.append(seq[i - 2] + seq[i - 1]), seq[i - 2])[1] for seq in [[0, 1]] for i in range(2, n)]

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

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

def eucl(x1, y1, x2, y2):
	return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

def choco(xa, ya, xb, yb, xc, yc, xd, yd):
	return 1 if abs((yb - ya) * (yd - yc) + (xb - xa) * (xd - xc)) < 1e-10 else 0

def pscl(num, l=[1]):
	for i in range(num):
		l = map(lambda x, y: x + y, [0] + l, l + [0])
	return l
(n, k) = map(int, input().split())
p = n
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
N = [i for i in range(n)]
ind = [0] * n
chk = set([])
d = {}
ans = 0
for i in N:
	tmp = a[i] - b[i]
	ind[i] = tmp
	if tmp in d:
		d[tmp].append(i)
	else:
		d[tmp] = [i]
		chk.add(tmp)
chk = list(chk)
chk.sort()
chk = chk[::-1]
for i in range(n):
	if i >= k and chk[-1] > 0:
		break
	ans += a[d[chk[-1]][-1]]
	d[chk[-1]].pop()
	p -= 1
	if len(d[chk[-1]]) == 0:
		del d[chk[-1]]
		chk.pop()
for i in range(p):
	ans += b[d[chk[-1]][-1]]
	d[chk[-1]].pop()
	if len(d[chk[-1]]) == 0:
		del d[chk[-1]]
		chk.pop()
print(ans)


from collections import namedtuple, deque
from operator import attrgetter
Cost = namedtuple('Cost', 'value position')

def minimal_summ(min_count, cost_during, cost_after):
	difference_cost = tuple((Cost(value_d - value_a, position) for (position, (value_d, value_a)) in enumerate(zip(cost_during, cost_after))))
	difference_cost = deque(sorted(difference_cost, key=attrgetter('value')))
	result = 0
	while len(difference_cost) > 0:
		item = difference_cost.popleft()
		if item.value <= 0:
			result += cost_during[item.position]
		elif min_count > 0:
			result += cost_during[item.position]
		else:
			difference_cost.append(item)
			break
		min_count -= 1
	while len(difference_cost) > 0:
		item = difference_cost.pop()
		result += cost_after[item.position]
	return result

def main():
	(generic_count, min_count) = map(int, input().strip().split())
	cost_during = tuple(map(int, input().split()))
	cost_after = tuple(map(int, input().split()))
	print(minimal_summ(min_count, cost_during, cost_after))
main()


def mult_mat(M1, M2):
	a11 = M1[0][0] * M2[0][0] + M1[0][1] * M2[1][0]
	a12 = M1[0][0] * M2[0][1] + M1[0][1] * M2[1][1]
	a21 = M1[1][0] * M2[0][0] + M1[1][1] * M2[1][0]
	a22 = M1[1][0] * M2[0][1] + M1[1][1] * M2[1][1]
	r = [[a11, a12], [a21, a22]]
	return r

def binpow(a, n):
	rez = [[a[0][0], a[0][1]], [a[1][0], a[1][1]]]
	s = bin(n)[3:]
	for i in s:
		rez = mult_mat(rez, rez)
		if i == '1':
			rez = mult_mat(rez, a)
	return rez[0][0]

def main():
	QWE = 'river'
	INF = 10 ** 18 + 9
	EPS = 10 ** (-9)
	import sys, math, re, urllib.request
	(n, m) = map(int, input().split(' ', 1))
	a = [int(i) for i in input().split(' ', n - 1)]
	b = [int(i) for i in input().split(' ', n - 1)]
	c = [0] * n
	q = 0
	for i in range(n):
		c[i] = a[i] - b[i]
		q += b[i]
	c.sort()
	i = 0
	while i < m or (i < n and c[i] < 0):
		q += c[i]
		i += 1
	print(q)
main()


from operator import itemgetter
(N, K) = [int(n) for n in input().split()]
aa = [int(n) for n in input().split()]
prices = [[aa[i], aa[i] - int(n)] for (i, n) in enumerate(input().split())]
prices = sorted(prices, key=itemgetter(1))
sum_n = 0
for (i, price) in enumerate(prices):
	if i < K:
		sum_n += price[0]
	elif price[1] > 0:
		sum_n += price[0] - price[1]
	else:
		sum_n += price[0]
print(sum_n)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
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 list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

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 pe(s):
	return print(str(s), file=sys.stderr)

def main():
	(n, k) = LI()
	a = LI()
	b = LI()
	c = sorted([a[i] - b[i] for i in range(n)])
	s = sum(b)
	for i in range(n):
		if i >= k and c[i] >= 0:
			break
		s += c[i]
	return s
print(main())


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = []
for q in range(n):
	d.append([b[q] - a[q], a[q], b[q]])
d.sort()
s = 0
for q in range(n - 1, -1, -1):
	if k > 0 or d[q][0] >= 0:
		s += d[q][1]
		k -= 1
	else:
		s += d[q][2]
print(s)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [b[i] - a[i] for i in range(n) if b[i] - a[i] < 0]
x.sort()
ans = sum(a) + sum(x[:n - k])
print(ans)


(elementCount, toBeBoughtFirst) = [int(x) for x in input().split(' ')]
firstWeekPrice = [int(x) for x in input().split(' ')]
secondWeekPrice = [int(x) for x in input().split(' ')]
priceDifference = []
for i in range(0, elementCount):
	priceDifference.append([firstWeekPrice[i] - secondWeekPrice[i], firstWeekPrice[i], secondWeekPrice[i]])
priceDifference.sort()
totalMoneySpent = 0
for i in range(0, toBeBoughtFirst):
	totalMoneySpent += priceDifference[i][1]
for i in range(toBeBoughtFirst, elementCount):
	if priceDifference[i][1] < priceDifference[i][2]:
		totalMoneySpent += priceDifference[i][1]
	else:
		totalMoneySpent += priceDifference[i][2]
print(totalMoneySpent)


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = []
for i in range(n):
	c.append([b[i] - a[i], a[i], b[i]])
c = sorted(c, key=lambda x: -x[0])
m = 0
for i in range(n):
	if i < k or c[i][1] <= c[i][2]:
		m += c[i][1]
	else:
		m += c[i][2]
print(m)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mas = [0] * n
S = 0
for i in range(n):
	mas[i] = a[i] - b[i]
	S += b[i]
mas.sort()
for i in range(n):
	if i < k or mas[i] < 0:
		S += mas[i]
print(S)


import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
decrease = [[0] * 2 for i in range(n)]
total = 0
pos = -1
for i in range(n):
	if a[i] <= b[i]:
		total += a[i]
		k -= 1
	else:
		pos += 1
		decrease[pos][0] = i
		decrease[pos][1] = a[i] - b[i]
if k > 0:
	decrease = sorted(decrease[:pos + 1], key=lambda x: x[1])
i = 0
for i in range(pos + 1):
	if k > 0:
		total += a[decrease[i][0]]
		k -= 1
	else:
		total += b[decrease[i][0]]
print(total)


(x, y) = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
arr3 = []
for i in range(0, x):
	p = [arr1[i], arr2[i], arr1[i] - arr2[i]]
	arr3.append(p)
arr3 = sorted(arr3, key=lambda z: z[0])
count = 0
s = 0
for i in range(0, len(arr3)):
	if arr3[i][2] <= 0:
		count += 1
		s = s + arr3[i][0]
	else:
		break
count1 = count
if count < y and y != 0:
	arr3 = arr3[count:]
	arr3 = sorted(arr3, key=lambda x: x[2])
	i = 0
	while count1 != y:
		s = s + arr3[i][0]
		count1 += 1
		i += 1
	while i != len(arr3):
		if arr3[i][0] <= arr3[i][1]:
			s = s + arr3[i][0]
		else:
			s = s + arr3[i][1]
		i += 1
	print(s)
else:
	for i in range(count, x):
		if arr3[i][0] <= arr3[i][1]:
			s = s + arr3[i][0]
		else:
			s = s + arr3[i][1]
	print(s)


(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
ans = sum(l2)
r1 = []
for i in range(n):
	r1.append(l1[i] - l2[i])
r1 = sorted(r1)
for i in range(n):
	if i < k or r1[i] < 0:
		ans += r1[i]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sum(b)
for i in range(n):
	a[i] -= b[i]
a.sort()
i = 0
while i < n:
	if i < k or a[i] < 0:
		c += a[i]
		i += 1
	else:
		break
print(c)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	b[i] -= a[i]
c = list(zip(a, b))
c = sorted(c, key=lambda x: -x[1])
ans = 0
z = 0
for i in range(n):
	if c[i][1] >= 0 or z < k:
		ans += c[i][0]
		z += 1
	else:
		ans += c[i][0] + c[i][1]
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cheaperA = set()
for i in range(n):
	if a[i] < b[i]:
		cheaperA.add((a[i], i))
	a[i] = (a[i], i)
	b[i] = (b[i], i)
out = 0
srtedA = sorted(a, key=lambda x: b[x[1]][0] - x[0], reverse=True)
bought = set()
for r in cheaperA:
	bought.add(r[1])
	out += r[0]
for i in range(n):
	if len(bought) >= k:
		break
	if not srtedA[i][1] in bought:
		bought.add(srtedA[i][1])
		out += srtedA[i][0]
for r in b:
	if not r[1] in bought:
		out += r[0]
print(out)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
profit = [(a[i] - b[i], a[i]) for i in range(n)]
res = 0
profit.sort()
for elem in profit:
	if k <= 0 and elem[0] > 0:
		res += elem[1] - elem[0]
	else:
		res += elem[1]
		k -= 1
print(res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(c, cost) = ([], 0)
for i in range(n):
	c.append([a[i] - b[i], i])
c.sort(key=lambda x: x[0])
i = 0
while i < n and (c[i][0] < 0 or k > 0):
	cost += a[c[i][1]]
	i += 1
	k -= 1
while i < n:
	cost += b[c[i][1]]
	i += 1
print(cost)


s = input().split()
(n, k) = map(int, s)
a = input().split()
a = list(map(int, a))
b = input().split()
b = list(map(int, b))
discounts = []
for i in range(n):
	info_pair = (b[i] - a[i], i)
	discounts.append(info_pair)
sorted_discounts = sorted(discounts, reverse=True)
idx_first_with_neg_discount = n
for idx in range(n):
	if sorted_discounts[idx][0] < 0:
		idx_first_with_neg_discount = idx
		break
if idx_first_with_neg_discount >= k:
	idx_last_buy_select = idx_first_with_neg_discount - 1
else:
	idx_last_buy_select = k - 1
money_spent = 0
for idx in range(idx_last_buy_select + 1):
	i = sorted_discounts[idx][1]
	money_spent += a[i]
for idx in range(idx_last_buy_select + 1, n):
	i = sorted_discounts[idx][1]
	money_spent += b[i]
print(money_spent)


(n, k) = input().split()
n = int(n)
k = int(k)
a = input().split()
b = input().split()

class item(object):

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

	def getC(self):
		return self.c
items = []
for i in range(len(a)):
	items.append(item(int(a[i]), int(b[i]), int(b[i]) - int(a[i])))
ans = 0
items.sort(key=item.getC, reverse=True)
for i in range(len(items)):
	if i < k:
		ans += items[i].a
	elif items[i].c > 0:
		ans += items[i].a
	else:
		ans += items[i].b
print(ans)


def solve(n, k, a, b):
	diff = []
	for i in range(n):
		diff.append(a[i] - b[i])
	zipped_list = zip(diff, a, b)
	sorted_pairs = sorted(zipped_list)
	tuples = zip(*sorted_pairs)
	(diff, a, b) = [list(tuple) for tuple in tuples]
	ans = sum(b)
	curr = 0
	for i in range(n):
		if curr < k or diff[i] < 0:
			ans += diff[i]
			curr += 1
	print(ans)
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
solve(n, k, a, b)


from sys import stdin, stdout
(n, k) = list(map(int, stdin.readline().split()))
sell_prices = list(map(int, stdin.readline().split()))
normal_prices = list(map(int, stdin.readline().split()))
diff = []
for (index, pair) in enumerate(zip(sell_prices, normal_prices)):
	bonus = pair[0] - pair[1]
	diff.append((index, bonus))
diff.sort(key=lambda x: x[1])
summ = 0
num_to_buy = 0
for (item, bonus) in diff:
	if num_to_buy < k or bonus < 0:
		summ += sell_prices[item]
		num_to_buy += 1
	else:
		summ += normal_prices[item]
stdout.write(str(summ))


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
m = []
res = 0
for i in range(n):
	m.append([B[i] - A[i], (A[i], B[i])])
m.sort(reverse=True)
for i in range(n):
	if i < k:
		res += m[i][1][0]
	else:
		res += min(m[i][1][0], m[i][1][1])
print(res)


I = lambda : list(map(int, input().split()))
(n, k) = I()
a = I()
b = I()
d = sorted([bb - aa for (bb, aa) in zip(b, a) if bb - aa < 0])
print(sum(a) + sum(d[:n - k]))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = []
for i in range(len(a)):
	diff.append((i, b[i] - a[i]))
diff = sorted(diff, reverse=True, key=lambda x: x[1])
total = 0
left = k
for i in range(len(a)):
	if left > 0 or diff[i][1] > 0:
		left -= 1
		total += a[diff[i][0]]
	else:
		total += b[diff[i][0]]
print(total)


(n, k) = map(int, input().split())
duringDiscount = list(map(int, input().split()))
afterDiscount = list(map(int, input().split()))
differences = []
for (i, item) in enumerate(zip(duringDiscount, afterDiscount)):
	differences.append((item[1] - item[0], i))
lista = sorted(differences, key=lambda x: x[0], reverse=True)
ans = 0
for (discount, index) in lista:
	if k > 0:
		ans += duringDiscount[index]
		k -= 1
	elif discount >= 0:
		ans += duringDiscount[index]
	else:
		ans += afterDiscount[index]
print(ans)


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
choices = []
dishonest = 0
money = 0
for i in range(n):
	choices.append([a[i] - b[i], a[i], b[i]])
	if a[i] - b[i] < 0:
		dishonest += 1
choices.sort(key=lambda x: x[0])
m = max(k, dishonest)
for i in range(m):
	money += choices[i][1]
for i in range(m, n):
	money += choices[i][2]
print(money)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] - b[i] for i in range(n)]
total = sum(a)
c.sort()
total_k = 0
for i in range(n):
	if c[i] > 0 and i >= k:
		break
	total_k = total_k + c[i]
total = total + total_k - sum(c)
print(total)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append(a[i] - b[i])
ls = zip(a, b, c)
ans = sorted(ls, key=lambda x: x[2])
result = 0
for i in ans:
	if i[2] < 0:
		result += i[0]
		k -= 1
	elif k > 0:
		result += i[0]
		k -= 1
	else:
		result += i[1]
print(result)


import functools as ft
(n, k) = tuple(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = list(zip(a, b))

def comparator(a, b):
	return a[0] - a[1] - (b[0] - b[1])
x.sort(key=ft.cmp_to_key(comparator))
i = 0
res = 0
while i < len(x) and (x[i][0] < x[i][1] or k > 0):
	res += x[i][0]
	k -= 1
	i += 1
while i < len(x):
	res += x[i][1]
	i += 1
print(res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lis = []
for i in range(n):
	lis.append([a[i] - b[i], i])
lis.sort()
res = 0
for i in range(n):
	if i < k or lis[i][0] < 0:
		res += a[lis[i][1]]
	else:
		res += b[lis[i][1]]
print(res)


def comp(e):
	return e[2]
s = input()
l = s.split()
n = int(l[0])
k = int(l[1])
s = input()
l = s.split()
v = [[0, 0, 0] for i in range(n)]
for i in range(n):
	v[i][0] = int(l[i])
s = input()
l = s.split()
for i in range(n):
	v[i][1] = int(l[i])
	v[i][2] = v[i][0] - v[i][1]
v.sort(key=comp)
i = 0
s = 0
while i < n and (v[i][2] <= 0 or k > 0):
	s += v[i][0]
	i += 1
	k -= 1
while i < n:
	s += v[i][1]
	i += 1
	k -= 1
print(s)