The marmots have prepared a very easy problem for this year's HC^2 – this one. It involves numbers n, k and a sequence of n positive integers a_1, a_2, ..., a_{n}. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also reads like a good criminal.

However I, Heidi, will have none of that. As my joke for today, I am removing the story from the statement and replacing it with these two unhelpful paragraphs. Now solve the problem, fools!


-----Input-----

The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a_1, ..., a_{n} (1 ≤ a_{i} ≤ 10^4).


-----Output-----

Output one number.


-----Examples-----
Input
8 5
1 1 1 1 1 1 1 1

Output
5
Input
10 3
16 8 2 4 512 256 32 128 64 1

Output
7
Input
5 1
20 10 50 30 46

Output
10
Input
6 6
6 6 6 6 6 6

Output
36
Input
1 1
100

Output
100

Difficulty: EASY
Tags: Sorting

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
firstLine = [int(x) for x in input().split()]
secondLine = [int(x) for x in input().split()]
print(sum(sorted(secondLine)[:firstLine[1]]))


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


a = input().split()
k = input().split()
s = []
for i in k:
	s.append(int(i))
s.sort()
d = 0
for i in range(int(a[1])):
	d += int(s.pop(0))
print(d)


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


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


def april(lst, k):
	return sum(sorted(lst)[0:k])
(n, k) = [int(i) for i in input().split()]
a = [int(j) for j in input().split()]
print(april(a, k))


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


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


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
sum = 0
for ki in range(k):
	minl = min(l)
	sum += minl
	l.remove(minl)
print(sum)


from heapq import nsmallest
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
print(sum(nsmallest(k, a)))


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


import math
import queue
from itertools import permutations
(n, k) = map(int, input().split())
a = [int(cost) for cost in input().split()]
a.sort()
sum = 0
for i in range(0, k):
	sum += a[i]
print(sum)


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


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


(n, k) = map(int, input().split())
(s, l) = (0, sorted(list(map(int, input().split()))))
while k:
	k -= 1
	s += l[k]
print(s)


n = [int(x) for x in input().split()]
(a, b) = (n[0], n[1])
l = [int(x) for x in input().split()]
l.sort()
print(sum(l[0:b]))


from sys import stdin

def get_ints():
	return list(map(int, stdin.readline().strip().split()))
(n, k) = get_ints()
ar = sorted(get_ints())
print(sum(ar[:k]))


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


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


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


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


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


from sys import stdin
for line in stdin:
	entrada = line.splitlines()
	break
n = int(entrada[0].split()[0])
k = int(entrada[0].split()[1])
numeros = [int(x) for x in input().split()]
numeros.sort()
suma = sum(numeros[:k])
print(suma)


import sys
n_k = [int(x) for x in sys.stdin.readline().split()]
k = n_k[1]
a = [int(x) for x in sys.stdin.readline().split()]
a = sorted(a)
k_smallest = sum(a[:k])
print(k_smallest)


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


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


import sys

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


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


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


v = int(input().split()[1].strip())
val = input().split()
val = sorted([int(x.strip()) for x in val])
print(sum(val[0:v]))


from sys import stdin
entrada = 0
sumatotal = 0
for line in stdin:
	linea1 = line.splitlines()
	break
a = int(linea1[0].split()[0])
b = int(linea1[0].split()[1])
arreglo = []
for x in input().split():
	arreglo.append(int(x))
arreglo.sort()
sumatotal = sum(arreglo[:b])
print(sumatotal)


(i_liczb, i_wziac) = map(int, input().split())
liczby = list(map(int, input().split()))
print(sum(sorted(liczby)[:i_wziac]))


nAndk = input().split()
(n, k) = [int(i) for i in nAndk]
inp = input().split()
num = [int(i) for i in inp]
num.sort()
ans = num[:k]
print(sum(ans))


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


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


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


import sys
mod = 1000000007

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

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

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

def print_array(a):
	print(' '.join(map(str, a)))

def main():
	(n, k) = get_ints()
	a = get_array()
	a.sort()
	s = 0
	for i in range(k):
		s += a[i]
	print(s)
main()


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


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
i = 0
while k > 0:
	ans += a[i]
	i += 1
	k -= 1
print(ans)


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


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


from sys import maxsize, stdout, stdin, stderr
import re
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 grid(r, c):
	return [lint() for i in range(r)]

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)))
(n, k) = tup()
ls = lint()
ls.sort()
s = 0
for i in range(k):
	s += ls[i]
print(s)


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


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


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import add
from itertools import accumulate
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
(n, k) = r()
arr = sorted(rr())
print(sum(arr[:k]))


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


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


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


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


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr
from bisect import bisect_left as bl, bisect_right as br

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

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

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

def binarytodecimal(n):
	return int(n, 2)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def ceildiv(x, y):
	return (x + y - 1) // y

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

def li():
	return sorted(list(map(int, input().split())))
(n, k) = di()
a = li()
print(sum(a[:k]))


(b, v) = map(int, input().split())
w = sorted(list(map(int, input().split())))
s = 0
for i in range(v):
	s += w[i]
print(s)


from sys import stdin, stdout
(n, k) = map(int, stdin.readline().split())
l = list(map(int, stdin.readline().split()))
l.sort()
stdout.write(str(sum(l[:k])))


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


def STR():
	return list(input())

def INT():
	return int(input())

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

def MAP2():
	return map(float, input().split())

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

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
(n, k) = MAP()
arr = LIST()
arr.sort()
sm = 0
for i in range(k):
	sm += arr[i]
print(sm)


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