Problem:


Score : 200 points

Problem Statement

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 1

5 3
50 100 80 120 80

Sample Output 1

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.

Sample Input 2

1 1
1000

Sample Output 2

1000



Sample input:
5 3
50 100 80 120 80


Sample output:
210

Submission status: Accepted

Solution code:
 
# from math import factorial as fac
from collections import defaultdict
# from copy import deepcopy
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
# print(f.readline())
sys.setrecursionlimit(10**2)

	
def print_case_iterable(case_num, iterable):
	print("Case #{}: {}".format(case_num," ".join(map(str,iterable))))

def print_case_number(case_num, iterable):
	print("Case #{}: {}".format(case_num,iterable))

def print_iterable(A):
	print (' '.join(A))

def read_int():
	return int(f.readline().strip())
def read_int_array():
	return [int(x) for x in f.readline().strip().split(" ")]
def rns():
	a =  [x for x in f.readline().split(" ")]
	return int(a[0]), a[1].strip()
def read_string():
	return list(f.readline().strip())
def ri():
	return int(f.readline().strip())
def ria():
	return [int(x) for x in f.readline().strip().split(" ")]
def rns():
	a =  [x for x in f.readline().split(" ")]
	return int(a[0]), a[1].strip()
def rs():
	return list(f.readline().strip())
def bi(x):
	return bin(x)[2:]





from collections import deque
import math
# NUMBER = 10**9 + 7
NUMBER = 998244353
def factorial(n) : 
	M = NUMBER
	f = 1
  
	for i in range(1, n + 1):  
		f = (f * i) % M # Now f never can  
						# exceed 10^9+7  
	return f
def mult(a,b):
	return (a * b) % NUMBER

def minus(a , b):
	return (a - b) % NUMBER

def plus(a , b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		g, y, x = egcd(b % a, a)
		return (g, x - (b // a) * y, y)

def modinv(a):
	m = NUMBER
	g, x, y = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m
def choose(n,k):
	if n < k:
		assert false
	return  mult(factorial(n), modinv(mult(factorial(k),factorial(n-k))))
from collections import deque, defaultdict 
import heapq


from types import GeneratorType
def bootstrap(f, stack=[]):
	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to

	return wrappedfunc


def dfs(g, timeIn, timeOut,depths,parents): 
	# assign In-time to node u 
	cnt = 0
	# node, neig_i, parent, depth
	stack = [[1,0,0,0]]
	while stack:
		v,neig_i,parent,depth = stack[-1]
		parents[v] = parent
		depths[v] = depth
		# print (v)
		if neig_i == 0:
			timeIn[v] = cnt    
			cnt+=1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i+=1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u,0,v,depth+1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1
  
def isAncestor(u: int, v: int, timeIn: list, timeOut: list) -> str: 
	return timeIn[u] <= timeIn[v] and timeOut[v] <= timeOut[u] 

cnt = 0
@bootstrap
def dfs(v,adj,timeIn, timeOut,depths,parents,parent=0,depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt+=1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u,adj,timeIn,timeOut,depths,parents,v,depth+1)
	timeOut[v] = cnt
	cnt+=1
	yield 


def solution(a,n,k):
	a.sort()
	return sum(a[:k])


	
def main():
	T = 1
	# T = ri()
	for i in range(T):
		# s = rs()
		# k = ri()
		n,k = ria()
		a=ria()

		x = solution(a,n,k)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			print >>output,str(x)# "Case #"+str(i+1)+':',
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()

if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
#example usage:
#    for l in res:
#       print >>output, str(len(l)) + ' ' +  ' '.join(l)

if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

def readInt():
	return int(input().strip())
	
def read():
	return input().strip()
	
def readList():
	return list(map(int, input().strip().split()))
	
[n, k] = readList()
arr = readList()

arr.sort()

print(sum(arr[:k]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

#=input()
#=int(input())
n,k=map(int,input().split())
p=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

p.sort()
ans = 0
for i in range(k):
    ans += p[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
ans = sum(a[:k])
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
l=list(map(int,input().split()))
l.sort()
print(sum(l[i] for i in range(k)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
sum = 0
k , n = map(int,input().split()) 
x = list(map(int,input().split()))
x.sort()

for i in range(n):
    sum += x[i]
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B - Mix Juice
def main():
    N, K, *P = map(int, open(0).read().split())
    P.sort()
    print(sum(P[:K]))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, k = rli()
	P = list(rli())
	P.sort()
	print(sum(P[i] for i in range(k)))
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))

p.sort();
c=0
for i in range(k):
  c+=p[i]
  
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
P = list(map(int,input().split()))
P.sort()
res = 0
i = 0
while(K):
    res += P[i]
    K -= 1
    i += 1
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()

summ = 0
for i in range(k):
    summ += p[i]

print(summ)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = [int(j) for j in input().split(' ')]
p = [int(j) for j in input().split(' ')]
 
p.sort()
sum = 0
 
for i in range(0,k):
  sum+=p[i]
  
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = [int(i) for i in input().split()]
dictionaire = {}
liste = []
prices = [int(x) for x in input().split()]
a = sorted(prices)

somme = sum(a[0:K])
print(somme)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
liste = [int(x) for x in input().split()]
roger = 0
for loop in range(k):
  roger += min(liste)
  liste.remove(min(liste))
print(roger)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
lis=list(map(int,input().split()))

ans=0
for i in range(k):
  mi=min(lis)
  ans+=mi
  lis.remove(mi)
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
print(sum(arr[:b]))

Submission status: Accepted

Solution code:
K = input()
A = K.split()
for i in range(len(A)):
    A[i] = int(A[i])

L = input()
B = L.split()
for i in range(len(B)):
    B[i] = int(B[i])
sortedb = sorted(B)

count = 0
summin = 0 
for i in range(len(B)):
    if count < A[1]:
        summin += sortedb[i]
        count += 1
print(summin)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
nums = list(map(int, input().split()))

print(sum(sorted(nums)[:k]))

Submission status: Accepted

Solution code:
# B
N, K = map(int, input().split())
A = list(map(int, input().split()))
sorted_list = sorted(A)
print(sum(sorted_list[:K]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
p=list(map(int,input().split()))
p.sort(key=int)
print(sum(p[0:K]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = sorted(list(map(int, input().split())))

print(sum(p[:k]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
in1 = input()
in2 = input()
NK_str = in1.split(" ")
p_str = in2.split(" ")
NK = [int(i) for i in NK_str]
p = [int(j) for j in p_str]
p.sort()
sum = 0
for i in range(NK[1]):
  sum += p[i]

print(sum)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())

p=list(map(int,input().split()))

p.sort()
ans=0
for i in range(k):
    ans+=p[i]
print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, K = map(int, input().split())
P = list(map(int, input().split()))

P.sort()

print(sum(P[:K]))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))

p.sort()
ans=0

for i in range(k):
  ans+=p[i]
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = list(map(int,input().split()))
p = list(map(int,input().split()))
p.sort()

print(sum(p[:k]))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict as dd

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



BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = input().split()

P = [int(p) for p in input().split()]

P.sort()

X = 0

for q in range(int(K)):
    X = X + P[q]

print(X)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=sorted(list(map(int,input().split())))
sum = 0
for i in range(K):
  sum += P[i]
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,K = LI()
p = LI()

p.sort()
print(sum(p[:K]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
s=list(map(int,input().split()))
s.sort()
ans=0
for i in range(b):
  ans=ans+s[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
p = list(map(int, input().split()))

print(sum(sorted(p)[:k]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, K = MI()
P = LMI()
P.sort()
print(sum(P[:K]))

Submission status: Accepted

Solution code:
N,K=[int(s) for s in input().split()]
p = [int(s) for s in input().split()]
total = 0

q = sorted(p)
for i in range(K):
    total += q[i]
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

p.sort()

print(sum(p[:k]))

Submission status: Accepted

Solution code:
N, K = list(map(int,input().split()))
p = list(map(int,input().split()))
sum = 0

for i in range(K):
  m=min(p)
  sum = sum + m
  p.pop(p.index(m))

print(sum)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

s = sorted(list(map(int, input().split())))

print(sum(s[0:k]))

Submission status: Accepted

Solution code:
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,K = map(int,S().split())
p = LI()
p = sorted(p)

print(sum(p[i] for i in range(K)))

Submission status: Accepted

Solution code:
N,K = input().split()
lists = []
B = 0

lists = list(map(int, input().split()))

lists.sort()
#print(lists)

for j in range(int(K)):
  B += int(lists[j])
 
print(B)

Submission status: Accepted

Solution code:
N, K, *p = map(int, open(0).read().split())

sortp = sorted(p)

ans = 0
for x in range(K):
    ans += sortp[x]
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=[int(i) for i in input().split()]

p.sort()
print(sum(p[:k]))

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
pl = list(map(int,input().split()))

pl = sorted(pl)

print(sum(pl[:k]))

Submission status: Accepted

Solution code:
import collections

N_syu, K_ko = map(int, input().split())
prices = list(map(int, input().split()))

prices.sort()

ans = sum(prices[:K_ko])
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
ans = 0

for i in range(k):
    ans += p[i]
    i += 1

print(ans)

Submission status: Accepted

Solution code:
N, K = input().split()
P = list(map(int,input().split()))

P.sort()
 
total=0

for i in range(int(K)):
    total=total+P[i]
 
print(total)

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np


def main():
	n,k=MI()
	p=LI()

	p.sort()

	print(sum(p[:k]))







if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
sum=0
for i in range(m):
  sum+=l[i]
print(sum)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
P = [int(i) for i in input().split()]

P.sort()

print(sum(P[:K]))

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
lol = [int(n) for n in input().split()]
lol.sort()
print(sum(lol[:b]))

Submission status: Accepted

Solution code:
n = input()
m = n.split()

a = [input() for l in range(0,1)]
b = a[0].split()


for i in range(0, len(b)):
    b[i] = int(b[i])

c = sorted(b, reverse=True)

p = 0
for i in range(int(m[0]) - int(m[1]),int(m[0])):
    p = p + int(c[i])
print(int(p))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
li = [int(i) for i in input().split()]
newlist = sorted(li)
price = 0
for a in range(k):
  price += newlist[a]
  
print(price)

Submission status: Accepted

Solution code:
str1 = list(map(int,input().split()))
str2 = list(map(int,input().split()))

list.sort(str2)

str3 = 0;

for i in str2[0:str1[1]]:
  str3 = str3+i
  
print(str3)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))

p.sort()
print(sum(i for i in p[:k]))

Submission status: Accepted

Solution code:
x, y = list(map(int, input().split()))
arr = list(map(int, input().split()))


def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr
    if(1 <= x, y <= 1000 and 1 <= max(arr) <= 1000 and 1 <= min(arr) <= 1000):
        ref = arr[0]
        ref_count = 0

        for ele in arr:
            if ele < ref:
                left.append(ele)
            elif ele > ref:
                right.append(ele)
            else:
                ref_count += 1
        left = quick_sort(left)
        right = quick_sort(right)
        return left + [ref] * ref_count + right


sorted_list = quick_sort(arr)

result = 0

for i in range(0, y):
    result += sorted_list[i]


print(result)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))

p = sorted(p)
ans = 0
for i in range(k):
    ans +=p[i]
print(ans)

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,k = mi()
p = li()

p.sort()

print(sum(p[:k]))

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
ans = 0
for i in range(b):
    ans += c[i]
print(ans)

Submission status: Accepted

Solution code:
n,k=(int(x) for x in input().split())
mylist=list(map(int, input().strip().split()))
mylist.sort()
num=0
suma=0
while num < k:
    suma=suma+mylist[num]
    num += 1
print(suma)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))

P.sort()
print(sum(P[:K]))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
if n==k and k==len(p):
        print(sum(p))
        exit()

if n>k:
    s=0
    for i in range(k):
        s+=p[i]
        
print(s)

Submission status: Accepted

Solution code:
n = list(int(num) for num in input().strip().split())
lst = list(int(num) for num in input().strip().split())[:n[0]]
result = []
for i in range(n[1]):
    temp = min(lst)
    result.append(temp)
    lst.remove(temp)
print(sum(result))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

str_list = list(input().split())

k = int(K)

list_sort = sorted(str_list, key=int)

list_sort_i = [int(s) for s in list_sort]

print(sum(list_sort_i[:k]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations
n,k = map(int,input().split())
list1 = list(map(int,input().split()))
print(sum(sorted(list1)[:k]))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
plist = []
tmp = input().split()
for i in range(N):
  plist.append(int(tmp[i]))
  
plist = sorted(plist)

ans = 0
for i in range(K):
  ans += plist[i]
 
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int,input().split()))

A_sorted = sorted(A)

result=sum(A_sorted[0:K])
print(result)

Submission status: Accepted

Solution code:
S = list(map(int, input().strip().split()))
N = S[0]
K = S[1]
p = list(map(int, input().strip().split()))
lists = []
for l in range(K):
  lists.append(min(p))
  p.remove(min(p))
  
print(sum(lists))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
p_desc = sorted(p)
sum = 0

for uni in p_desc[0:K]:
  sum += uni

print(sum)

Submission status: Accepted

Solution code:
n, k =  map(int, input().split())
p = list(map(int,input().split()))

p.sort()

ans = 0

for i in range(k):
  ans += p[i]
  
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
li = list(input().split())

li.sort(key = int)

j = 0
i = 0

while i <= k-1:
  
  j += int(li[i])
  i += 1

print(j)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
p = [int(i) for i in input().split()]
p.sort()
ans = 0

if K == 1:
    print(p[0])
elif K == 2:
    print(p[0]+p[1])
else:
    for i in range(K):
        ans += p[i]
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=input().split()
p2=[]
for i in range(n):
  p3=int(p[i])
  p2.append(p3)
p1=sorted(p2)
c = 0
for i in range(k):
  c += int(p1[i])
print(c)

Submission status: Accepted

Solution code:
A=list(input().split(" "))
B=list(input().split(" "))
for i in range(len(B)):
    B[i]=int(float(B[i]))
C=sorted(B)
D=[]
M=0
for i in range(int(A[1])):
    D.append(int(C[i]))
for j in range(len(D)):
    M=D[j]+M
print(M)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
x = sorted(list(map(int, input().split())))
c = 0
for i in range(b):
  c += x[i]
print(c)

Submission status: Accepted

Solution code:
n = input()
m = n.split()
a = [input() for l in range(0,1)]
b = a[0].split()
for i in range(0, len(b)):
    b[i] = int(b[i])
c = sorted(b, reverse=True)
p = 0
for i in range(int(m[0]) - int(m[1]),int(m[0])):
    p = p + int(c[i])
print(p)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
array = list(map(int, input().split()))
array.sort()
del array[b:]
print(sum(array))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
p = [int(a) for a in input().split()]
p_s = sorted(p)
print(sum(p_s[:K]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = sorted(list(map(int, input().split())))

ans = 0
for i in range(k):
    ans += p[i]

print(ans)

Submission status: Accepted

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