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: interview

Starter code:

Solutions:
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()))
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]]
    else:
        if 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)

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)


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 = list(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)


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]))


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))

read=lambda:list(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 = 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]))      


from sys import stdin, stdout

n,k = list(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: # Then he simply spends on all item which are cheaper
    totalSpend=0
    for i in range(n):
        totalSpend+=min([a[i],b[i]])
else: # Now we need to find the k biggest cost differential
    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())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
ans = sum(b)
for i in range(n):
    c[i] = a[i] - b[i]
c.sort()
i = 0
while (i < k) or (i < n and c[i] < 0):
    ans += c[i]
    i += 1
print(ans)

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()))

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)

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)


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)
# print(c)
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())

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=list(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(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 = list(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)]
ans = sum(b)
c.sort()
ans += sum(c[:k])
i = k
while i < n and c[i] < 0:
    ans += c[i]
    i += 1
print(ans)


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)]

#print(k)
#print(a)
#print(b)
#print(diff)

index = sorted(list(range(len(diff))), key=lambda x: diff[x])
#print(index)

cheat = len([x for x in diff if x < 0])
#print(cheat)
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(bnow)
#print(blater)

print(sum(bnow) + sum(blater))



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])
# купить не менее k товаров
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:]))



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()

def solve():
	N, K = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	# K <= N <= 2*10^5
	# Ai, Bi <= 10^4

	C = [a[0]-a[1] for a in zip(A, B)] 

	D = list(zip(list(range(N)), C)) # (index, loss)

	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()



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], 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)