AtCoder Beginner Contest 171 - Mix Juice

A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots, p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of those fruits.

-----Constraints-----
 - 1 \leq K \leq N \leq 1000
 - 1 \leq p_i \leq 1000
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N

-----Output-----
Print an integer representing the minimum possible total price of fruits.

-----Sample Input-----
5 3
50 100 80 120 80

-----Sample Output-----
210

This shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen, and 80 yen, respectively.
The minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen when choosing Fruit 1, 3, and 5.

Source: atcoder | Difficulty: EASY


Solutions:
(n, k) = map(int, input().split())
p = [int(i) for i in input().split()]
p = sorted(p)
print(sum(p[:k]))


import itertools
[N, K] = [int(i) for i in input().split()]
price = [int(i) for i in input().split()]
price.sort()
sum = 0
for i in range(K):
	sum += price[i]
print(sum)


(n, k) = list(map(int, input().split()))
print(sum(sorted(map(int, input().split()))[:k]))


(n, m) = map(int, input().split())
l = sorted(list(map(int, input().split())))
print(sum(l[0:m]))


(N, K) = map(int, input().split())
print(sum(sorted(list(map(int, input().split())))[0:K]))


(N, M) = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
print(sum(l[0:M]))


(N, K) = list(map(int, input().split()))
P = list(map(int, input().split()))
P.sort()
print(sum(P[0:K]))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
price = 0
for i in range(k):
	price += l[i]
print(price)


(n, k) = map(int, input().split())
a = [int(v) for v in input().split()]
a.sort()
print(sum(a[:k]))


n = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()
print(sum(p[:n[1]]))


(n, k) = list(map(int, input().split()))
m = list(map(int, input().split()))
m.sort()
print(sum(m[:k]))


(n, k) = map(int, input().split())
P = [int(i) for i in input().split()]
P.sort()
print(sum(P[:k]))


(n, k) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
s = 0
for i in range(k):
	s += p[i]
print(s)


(N, K) = map(int, input().split())
p = list(map(int, input().split()))
print(sum(sorted(p)[:K]))


(N, K) = map(int, input().split())
L = list(map(int, input().split()))
L.sort()
S = L[:K]
print(sum(S))


(n, k, *P) = map(int, open(0).read().split())
P.sort()
print(sum(P[:k]))


(n, k) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
print(sum(p[:k]))


(_, K, *P) = map(int, open(0).read().split())
print(sum(sorted(P)[:K]))


(N, K) = map(int, input().split())
P = map(int, input().split())
print(sum(sorted(P)[:K]))


(n, k) = map(int, input().split())
a = sorted(map(int, input().split()))
print(sum(a[:k]))


(n, k) = map(int, input().split())
p = list(map(int, input().split()))
q = sorted(p)[:k]
print(sum(q))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 0
for i in range(k):
	count += a[i]
print(count)


(n, k, *l) = map(int, open(0).read().split())
l.sort()
print(sum(l[:k]))


(n, k) = map(int, input().split())
ppp = list(map(int, input().split()))
ppp.sort()
print(sum(ppp[:k]))


from typing import List

def answer(n: int, k: int, p: List[int]) -> int:
	return sum(sorted(p)[:k])

def main():
	(n, k) = list(map(int, input().split()))
	p = list(map(int, input().split()))
	print(answer(n, k, p))

def __starting_point():
	main()
__starting_point()


import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
(n, k) = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
tmp = 0
res = 0
P = sorted(P)
res = sum(P[:k])
print(res)


(a, b, *c) = map(int, open(0).read().split())
print(sum(sorted(c)[:b]))


(n, m) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
print(sum(arr[:m]))


(N, K) = map(int, input().split())
print(sum(sorted([int(a) for a in input().split()])[:K]))


(a, b) = map(int, input().split())
C = list(map(int, input().split()))
D = sorted(C)
print(sum(D[:b]))


(x, y) = map(int, input().split())
t = list(map(int, input().split()))
t.sort()
print(sum(t[:y]))


a = list(map(int, input().split()))
N = a[0]
K = a[1]
p = list(map(int, input().split()))
p.sort()
x = 0
for i in range(K):
	x += p[i]
print(x)


(n, k) = map(int, input().split())
p = [int(i) for i in input().split()]
p.sort()
print(sum(p[0:k]))


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
print(sum(A[:K]))


(n, k) = list(map(int, input().split()))
p = list(map(int, input().split()))
ans = 0
l = list()
for i in range(k):
	l.append(min(p))
	p.remove(min(p))
ans = sum(l)
print(ans)


(N, K) = map(int, input().split())
A = [int(x) for x in input().split()]
print(sum(sorted(A)[:K]))


(N, K) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
a = a[:K]
print(sum(a))


(n, k) = map(int, input().split())
p = list(map(int, input().split()))
p2 = sorted(p)
print(sum(p2[:k]))


(n, k, *p) = map(int, open(0).read().split())
p.sort()
a = sum(p[:k])
print(a)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, bisect
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
stdin = sys.stdin
ni = lambda : int(ns())
nf = lambda : float(ns())
na = lambda : list(map(int, stdin.readline().split()))
nb = lambda : list(map(float, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
(N, K) = na()
p = na()
print(sum(sorted(p)[:K]))


(n, k) = map(int, input().split())
l = []
l = list(map(int, input().split()))
l.sort()
print(sum(l[0:k]))


(n, k, *a) = map(int, open(0).read().split())
print(sum(sorted(a)[:k]))


(N, K) = map(int, input().split())
p = sorted((int(i) for i in input().split()))
print(sum(p[:K]))


(_, k) = map(int, input().split())
a = sorted((int(i) for i in input().split()))
print(sum(a[:k]))


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
c = sorted(c)
print(sum(c[0:b]))


(N, K) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
sum = 0
for i in range(K):
	sum += p[i]
print(sum)


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
print(sum(c[0:b]))


foo = list(input().split())
K = int(foo[1])
P = sorted(map(int, list(input().split())))
i = 0
total = int(0)
while i < K:
	total = total + int(P[i])
	i += 1
print(total)


(N, K) = map(int, input().split())
p = sorted([int(i) for i in input().split()])
ans = 0
for i in range(K):
	ans += p[i]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
print(sum(sorted(a)[0:k]))


(N, K) = map(int, input().split())
n = list(map(int, input().split()))
m = sorted(n)
print(sum(m[0:K]))


(n, need) = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
ans = 0
for i in range(need):
	ans += li[i]
print(ans)


def i_input():
	return int(input())

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

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

def i_row(N):
	return [int(input()) for _ in range(N)]

def i_row_list(N):
	return [list(map(int, input().split())) for _ in range(N)]
(n, k) = i_map()
pp = i_list()
pp.sort()
ans = 0
for i in range(k):
	ans += pp[i]
print(ans)


n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
p = sorted(p)
val = sum(p[:n[1]])
print(val)


(n, k) = map(int, input().split())
p = [int(x) for x in input().split()]
p.sort()
q = p[:k]
print(sum(q))


(N, K) = map(int, input().split())
p = list(map(int, input().split()))
sp = sorted(p)
goukei = 0
for i in range(K):
	goukei += sp[i]
print(goukei)


(n, k) = map(int, input().split())
(*P,) = map(int, input().split())
P.sort()
print(sum(P[:k]))


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
print(sum(A[0:k]))


(N, K) = map(int, input().split())
ps = sorted(map(int, input().split()))
print(sum(ps[:K]))


(N, K) = map(int, input().split())
fruit = [int(i) for i in input().split()]
fruit.sort()
price = 0
for i in range(N):
	if i > K - 1:
		break
	price += fruit[i]
print(price)


(n, k) = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
print(sum(li[:k]))


(n, k) = map(int, input().split())
F = list(map(int, input().split()))
F.sort()
print(sum(F[:k]))


(n, k) = map(int, input().split())
a = sorted([int(x) for x in input().split()])
print(sum(a[:k]))


(n, k) = map(int, input().split())
p = sorted(list(map(int, input().split())))
p = p[0:k]
print(sum(p))


n = input().split()
p = input().split()
n = [int(i) for i in n]
p = [int(i) for i in p]
p = sorted(p)
num = n[1]
total = p[0:num]
total_price = sum(total)
print(total_price)


(N, K) = map(int, input().split())
prices = list(map(int, input().split()))
prices.sort()
print(sum(prices[:K]))


(_, k) = input().split()
k = int(k)
p = sorted(list((int(i) for i in input().split())))
print(sum(p[0:k]))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l1 = sorted(l)
print(sum(l1[:m]))


k = int(input().split(' ')[1])
print(sum(sorted([int(n) for n in input().split(' ')])[0:k]))


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
print(sum(A[:K]))


(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
result = 0
for data in range(k):
	result += l[data]
print(result)


(n, k) = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
ans = 0
for i in range(k):
	x = P[i]
	ans += x
print(ans)


(_, b, *c) = map(int, open(0).read().split())
print(sum(sorted(c)[:b]))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
print(sum(a[:m]))


(n, k) = map(int, input().split())
p = list(map(int, input().split()))
p = sorted(p)
price = 0
for i in range(k):
	price += p[i]
print(price)


(N, K) = map(int, input().split())
(*p,) = map(int, input().split())
p.sort()
print(sum(p[:K]))


(a, b) = map(int, input().split())
p = map(int, input().split())
X = sorted(p)[:b]
print(sum(X))


(n, k, *p) = map(int, open(0).read().split())
print(sum(sorted(p)[:k]))


(n, k) = map(int, input().split())
pp = sorted(map(int, input().split()))
print(sum(pp[:k]))


(a, b, *l) = map(int, open(0).read().split())
print(sum(sorted(l)[:b]))


(N, K) = map(int, input().split())
F = sorted(list(map(int, input().split())))[:K]
print(sum(F))


(N, K) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
print(sum(s[:K]))


(A, B) = map(int, input().split())
L = list(map(int, input().split()))
L.sort()
print(sum(L[:B]))


(x, y) = map(int, input().split())
s = sorted(list(map(int, input().split())))
print(sum(s[:y]))


k = int(input().split()[1])
print(sum(sorted(map(int, input().split()))[:k]))


(n, k) = map(int, input().split())
lst = sorted(map(int, input().split()))
print(sum(lst[:k]))


(n, k) = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort(reverse=False)
ans = 0
for i in range(k):
	ans += p[i]
print(ans)


(N, K) = (int(x) for x in input().split())
p = list(map(int, input().split()))
ans = 0
p.sort()
for i in range(0, K):
	ans += p[i]
print(ans)


(a, b) = map(int, input().split())
N = sorted(list(map(int, input().split())))
print(sum(N[0:b]))


(n, k) = list(map(int, input().split()))
pArr = list(map(int, input().split()))
pArr.sort()
ans = 0
for i in range(k):
	ans += pArr[i]
print(ans)


(N, K) = map(int, input().split())
p = sorted(map(int, input().split()))
print(sum(p[0:K]))


(_, k) = map(int, input().split())
(*p,) = map(int, input().split())
print(sum(sorted(p)[:k]))


(N, K) = map(int, input().split())
p = tuple(map(int, input().split()))
print(sum(sorted(p)[:K]))


(n, m) = map(int, input().split())
a = sorted(list(map(int, input().split())))
print(sum(a[:m]))


(n, k) = map(int, input().split())
p = map(int, input().split())
sp = sorted(p)
score = 0
for i in range(k):
	score += sp[i]
print(score)


R = lambda : map(int, input().split())
(n, k) = R()
print(sum(sorted(R())[:k]))


from itertools import accumulate
(N, K) = map(int, input().split())
P = [0] + list(accumulate(sorted(map(int, input().split()))))
print(P[K])


(N, K) = (int(x) for x in input().split())
p = list(map(int, input().split()))
p.sort()
print(sum(p[:K]))


(N, K) = map(int, input().split())
p = list(map(int, input().split()))
pa = sorted(p)
print(sum(pa[0:K]))


(n, k) = map(int, input().split())
v = list(map(int, input().split()))
v.sort()
print(sum(v[:k]))


b = int(input().split()[-1])
print(sum(sorted(map(int, input().split()))[:b]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
print(sum(a[:k]))


I = lambda : list(map(int, input().split()))
(n, k) = I()
l = sorted(I())
print(sum(l[:k]))


(n, k) = map(int, input().split())
x = [int(x) for x in input().split()]
x.sort()
print(sum(x[0:k]))


(n, k) = map(int, input().split())
p = sum(sorted(map(int, input().split()))[:k])
print(p)


(N, K, *p) = map(int, open(0).read().split())
p.sort()
print(sum(p[:K]))


(N, K, *P) = map(int, open(0).read().split())
print(sum(sorted(P)[:K]))


(N, N) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
print(sum(p[:N]))


(N, K) = map(int, input().split())
fruit = input().split()
fruit = [int(x) for x in fruit]
fruit.sort()
print(sum(fruit[:K]))


(_, k, *p) = map(int, open(0).read().split())
p.sort()
print(sum(p[:k]))


(N, K) = [int(i) for i in input().split(' ')]
p = [int(i) for i in input().split(' ')]
p.sort()
print(sum(p[:K]))


(n, k) = input().split()
p = [int(i) for i in input().split()]
int_k = int(k) - 1
p = sorted(p)
print(sum(p[0:int(k)]))


(N, K) = map(int, input().split())
L = list(map(int, input().split()))
L = sorted(L)
print(sum(L[:K]))


import numpy as np
(n, k) = list(map(int, input().split()))
fruits = np.array(input().split(), dtype=np.int64)
fruits.sort()
ans = 0
cnt = 0
for i in fruits:
	if cnt < k:
		ans += i
		cnt += 1
print(ans)


import sys
sys.setrecursionlimit(1000000)
from collections import deque
(N, K) = list(map(int, input().split()))
data = list(map(int, input().split()))
data.sort()
ans = 0
for i in range(K):
	ans += data[i]
print(ans)


(_, K) = map(int, input().split())
(*P,) = map(int, input().split())
P.sort()
print(sum(P[:K]))


(a, b) = map(int, input().split())
l = [int(i) for i in input().split()]
l.sort()
print(sum(l[:b]))


(N, K) = map(int, input().split())
Ps = sum(sorted(list(map(int, input().split())))[:K])
print(Ps)


import numpy as np
(N, K) = map(int, input().split())
p = list(map(int, input().split()))
print(np.sum(sorted(p)[:K]))


(n, k) = map(int, input().split())
ps = sorted(map(int, input().split()))
print(sum(ps[:k]))


(N, K) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
m = sum(p[:K])
print(m)


(n, k, *l) = map(int, open(0).read().split())
l1 = sorted(l)
print(sum(l1[:k]))


(_, k) = list(map(int, input().split()))
print(sum(sorted(list(map(int, input().split())))[0:k]))


(n, k) = map(int, input().split())
pp = list(map(int, input().split()))
sp = sorted(pp)
ans = sum(sp[:k])
print(ans)


(N, K) = map(int, input().split())
P = list(map(int, input().split()))
assert len(P) == N
P = sorted(P)
print(sum(P[:K]))


(x, y) = map(int, input().split())
n = sorted(list(map(int, input().split())))
print(sum(n[:y]))


(a, b) = map(int, input().split())
c = sorted(map(int, input().split()))
print(sum(c[:b]))


(N, K) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
print(sum(a[:K]))


(N, K, *X) = map(int, open(0).read().split())
X.sort()
print(sum(X[:K]))


(n, k) = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
print(sum(x[:k]))


(n, k) = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
sum = 0
for i in range(k):
	sum += li[i]
print(sum)


numline = input().split(' ')
a = int(numline[0])
b = int(numline[1])
numline = input().split(' ')
numlis = []
for i in range(a):
	numlis.append(int(numline[i]))
numlis.sort()
result = 0
for i in range(b):
	result += numlis[i]
print(result)


(N, K) = map(int, input().split())
ps = list(map(int, input().split()))
ps.sort()
print(sum(ps[:K]))


(n, k) = map(int, input().split())
l = sorted(list(map(int, input().split())))
print(sum(l[0:k]))


(N, K) = map(int, input().split())
p = list(map(int, input().split()))
res_list = []
for i in p:
	r = int(i)
	res_list.append(r)
res_list.sort()
print(sum(res_list[0:K]))


(n, k) = map(int, input().split())
pi = list(map(int, input().split()))
pi.sort()
print(sum(pi[:k]))


(N, K) = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
print(sum(X[0:K]))


import numpy as np
d = [int(x) for x in input().split(' ')]
K = d[1]
d = np.array([int(x) for x in input().split(' ')])
print(np.sort(d)[:K].sum())


l = list(map(int, open(0).read().split()))
print(sum(sorted(l[2:])[:l[1]]))


(n, k) = map(int, input().split())
P = sorted(map(int, input().split()))
print(sum(P[:k]))


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
print(sum(l[0:b]))


I = lambda : map(int, input().split())
(_, k) = I()
print(sum(sorted(I())[:k]))


(a, b) = map(int, input().split())
l = sorted(list(map(int, input().split())))
print(sum(l[:b]))


(N, K) = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
print(sum(lst[:K]))


(N, K) = map(int, input().split())
p = list(map(int, input().split()))
P = p.sort()
ans = sum(p[:K])
print(ans)


(N, K) = map(int, input().split())
poe = list(map(int, input().split()))
poe = sorted(poe)
print(sum(poe[:K]))


(k, n) = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
sum = 0
for i in range(n):
	p = x[i]
	sum += p
print(sum)


(n, k) = map(int, input().split())
prices = sorted(map(int, input().split()))
print(sum(prices[:k]))


(N, K) = map(int, input().split())
n = map(int, input().split())
A = sorted(n)
print(sum(A[:K]))


(n, k) = map(int, input().split())
P = sorted(list(map(int, input().split())))
print(sum(P[0:k]))


(n, k) = map(int, input().split())
price = list(map(int, input().split()))
count = 0
sum = 0
while count < k:
	abc = min(price)
	sum += abc
	price.pop(price.index(abc))
	count += 1
print(sum)


(N, K) = map(int, input().split())
P = list(map(int, input().split()))
P = sorted(P)
ans = sum(P[0:K])
print(ans)


(n, k) = map(int, input().split())
p = list(map(int, input().split()))
ps = sorted(p)
print(sum(ps[:k]))


import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque, Counter
from decimal import Decimal
import functools

def v():
	return input()

def k():
	return int(input())

def S():
	return input().split()

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

def X():
	return list(input())

def L():
	return list(input().split())

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

def lcm(a, b):
	return a * b // math.gcd(a, b)
sys.setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7
cnt = 0
ans = 0
inf = float('inf')
al = 'abcdefghijklmnopqrstuvwxyz'
AL = al.upper()
(N, M) = I()
A = l()
A.sort()
ans = 0
for i in range(M):
	ans += A[i]
print(ans)


(_, K) = map(int, input().split())
print(sum(sorted(map(int, input().split()))[:K]))


(n, k) = map(int, input().split())
L = list(map(int, input().split()))
L.sort()
print(sum(L[:k]))


(N, K) = map(int, input().split())
L = list(map(int, input().split()))
L.sort()
print(sum(L[0:K]))


(n, k) = map(int, input().split())
nl = list(map(int, input().split()))
nl.sort()
print(sum(nl[:k]))


(n, k) = list(map(int, input().split()))
b = list(map(int, input().split()))
b.sort()
d = 0
for a in range(k):
	d = d + b[a]
print(d)


(n, m) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
print(sum(p[0:m]))


(N, K) = list(map(int, input().split()))
l = list(map(int, input().split()))
S = sorted(l)
sums = sum(S[:K])
print(sums)


(n, k) = map(int, input().split())
r = list(map(int, input().split()))
r.sort()
print(sum(r[:k]))


(_, K) = map(int, input().split())
p = sorted(list(map(int, input().split())))
print(sum(p[:K]))


import sys, os.path
sys.setrecursionlimit(10 ** 5)

def mod():
	return 10 ** 9 + 7

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

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

def li():
	return list(sys.stdin.readline().strip())

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

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

def solve():
	(n, k) = mii()
	b = 0
	a = sorted(lii())
	for i in range(k):
		b += a[i]
	print(b)
for _ in range(1):
	solve()


(a, b) = map(int, input().split())
s = list(map(int, input().split()))
w = []
for i in range(b):
	w.append(min(s))
	s.remove(min(s))
print(sum(w))


N = list(map(int, input().split()))
P = list(map(int, input().split()))
print(sum(sorted(P)[:N[1]]))


(N, K) = map(int, input().split())
(*P,) = map(int, input().split())
P.sort()
print(sum(P[:K]))


(a, b) = input().split()
n = sorted([int(x) for x in input().split()])
print(sum(n[:int(b)]))


(N, K, *P) = map(int, open(0).read().split())
P.sort()
print(sum(P[:K]))


(n, m) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
ans = 0
for i in range(m):
	ans += p[i]
print(ans)