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:
n,k = map(int,input().split())
if n==1:
    print(int(input()))
else:
    total = 0
    lis = list(map(int,input().split()))
    lis.sort()
    for i in range(k):
        total += lis[i]
    print(total)

Submission status: Accepted

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

result = 0

for _ in range(k):
  min_p = min(p)
  index = p.index(min_p)
  p.pop(index)
  result += min_p

print(result)

Submission status: Accepted

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

la = sorted(a)
ans = 0
for i in range(k):
    ans += la[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[0:K]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math
import collections
import bisect


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import itertools

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N, K = MI()
    p = LI()
    ps = sorted(p)
    ans = 0

    for i in range(K):
        ans += ps[i]

    print(ans)
    #print(len(clist))
    #print(sum(clist[2]))



if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
N,K=map(int, input().split())
A=list(map(int, input().split()))
A.sort()
ans=0
n=0
for n in range(K):
    ans+=A.pop(0)
print(ans)

Submission status: Accepted

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

print(sum)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
d = []
d= list(map(int, input().split()))


d.sort()
a = 0
for i in range(n):
    a = a + d[i]
print(a)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
 
s = input().rstrip().split(' ')
st = []
 
for i in range(0,n):
  a = int(s[i]) 
  st.append(a)
 
new_st = sorted(st)
sum = 0
for j in range(0,k):
  sum += new_st[j]
  
print(sum)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
import sys
if N==1:
    print(input())
    sys.exit()
list = input().split()
MIN = 1001
SUM = 0
for j in range(0,K):
  for i in list:
    if MIN > int(i):
      MIN = int(i)
  list.remove(str(MIN))
  SUM += MIN
  MIN = 1001
print(SUM)

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:
# -*- coding: utf-8 -*-
#種類の数を取得
kind = input().split()
kind_int = [int(l) for l in kind]
#価格を取得
price = input().split()
price_int = [int(l) for l in price]
price_int.sort()
#必要な分だけ取り出して合計
price_int_2 = price_int[0:kind_int[1]]
print(sum(price_int_2))

Submission status: Accepted

Solution code:
k = 0
a = input().split(" ")
b = input().split(" ")
g = int(a[0])
f = int(a[1])
i = 0
d = []
while i < g :
    d.append(int(b[i]))
    i = i + 1
x = sorted(d)
i = 0
while i < f :
    k = k + x[i]
    i = i + 1
print(k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = input().split()
b = input().split()

a = [int(x) for x in a]
b = [int(x) for x in b]

a = a[1]
b.sort()

output = sum(b[0:a])
print(output)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = []
a = input().split()
N = int(a[0])
K = int(a[1])
p = []
p = input().split()
p = [int(i) for i in p]

#print('N=', N, 'K=', K)
#print('p', p)

p.sort()
#print('sortp', p)

total = 0

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

print(total)

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 = 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 = list(map(int, input().split(" ")))
price = list(map(int, input().split(" ")))
minimum = 0
for i in range(n):
    swap = False
    for j in range(0, n-i-1):
        if price[j]>price[j+1]:
            price[j], price[j+1] = price[j+1], price[j]
            swap = True
    if swap == False:
        break
        
for i in range(k):
    minimum += price[i]
print(minimum)

Submission status: Accepted

Solution code:
no, sct = map(int, input().split(' '))
flut = list(map(int, input().split(' ')))
flut = sorted(flut, reverse=False)
sum_ = 0
for i in range(sct):
  sum_ += flut[i]
print(sum_)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
fruitPrice = list(map(int,input().split()))
fruitPrice.sort()
reversed(fruitPrice)
minimum = fruitPrice[0:K]

print(sum(minimum))

Submission status: Accepted

Solution code:
def sol():
    n,k=map(int,input().split())
    A=[int(i) for i in input().split()]
    A.sort()
    s=0
    for i in range(k):s+=A[i]
    print(s)
if(__name__=='__main__'):
    sol()

Submission status: Accepted

Solution code:
import copy as cp
N,K = input().split()
P = input().split()
# P=(int(x) for x in input().split())
PP = [int(n) for n in P]
# print(PP)
print(sum(sorted(PP)[0:int(K)]))
# print(PP)
# C = sorted(PP)
# print(C[0:int(K)])
# ll=cp.copy(sorted(P))
# aa = [50, 80, 80, 100, 120]
# print(ll[0:2])
# print(aa[0:2])
# print(P)

Submission status: Accepted

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

bag = []
bag_max = 0

for i in range(n):

    if i < k:
        bag.append(p[i])
        if bag_max < p[i]:
            bag_max = p[i]
    else:
        if bag_max > p[i]:
            bag.append(p[i])
            bag.remove(bag_max)
            bag_max = max(bag)

print(sum(bag))

Submission status: Accepted

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

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

sortp = sorted(p)

print(sum(sortp[0:K]))

Submission status: Accepted

Solution code:
import numpy as np
n, k = list(map(int, input().rstrip().split()))
p = list(map(int, input().rstrip().split()))
p = np.sort(np.array(p))
 
print(np.sum(p[:k]))

Submission status: Accepted

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

newP = P.sort()
sum_yen = 0

for i in range(K):
    sum_yen += P[i]

print(sum_yen)

Submission status: Accepted

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

Submission status: Accepted

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

p_ = p[0:k]
print(sum(p_))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq

def main():
    N, K = map(int, input().split())
    P = list(map(int, input().strip().split()))

    array = (heapq.nsmallest(K, P))
    print(sum(array))

main()

Submission status: Accepted

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

num_list.sort()
min_list = num_list[:k]
min = sum(min_list)
print(min)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n, k = rm()
li = rl()
li.sort()
li = li[:k]
print(sum(li))

Submission status: Accepted

Solution code:
a = input().split()
b = int(a[0])
c = int(a[1])
d = [int(i) for i in input().split()]
D = sorted(d)


print(sum(D[0:c]))

Submission status: Accepted

Solution code:
n, k = input().split()
n = int(n)
k = int(k)
listnum = input().split()
newlist = []
sumnum = 0

listnum = [int(n) for n in listnum]
newlist = sorted(listnum)
for b in range(k):
    sumnum = sumnum + newlist[b]
print(sumnum)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
# debug = lambda *a, **kw: print(*a, **kw, file=sys.stderr)

N, K = inm()
P = inl()
P.sort()


def solve():

    return sum(P[:K])


print(solve())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

A_sorted = sorted(A)

minSum = 0

for i in range(K):
    minSum += A_sorted[i]

print(minSum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = [int(s) for s in input().split()]
print(sum(sorted([int(s) for s in input().split()])[:K]))

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 = (int(x) for x in input().split())
P = list(map(int, input().split()))
import heapq
Y = (heapq.nsmallest(K, P))
print(sum(Y))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin

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

prices = sorted(prices)

sum = 0
for i in range(0, K):
    sum += prices[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:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

ans = 0

B=sorted(A)

for a in B[:K]:
  ans += a
  if ans > 10**18:
    print('-1')
    break
else:
  print(ans)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
p_n = list(map(int, input().split()))
ans  = 0
p_n.sort()

for i in range(K):
    ans += p_n[i]

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce

N, K = [int(x) for x in input().split()]
P = sorted([int(x) for x in input().split()])
print(reduce(lambda x, y: x + y, P[0:K]))

Submission status: Accepted

Solution code:
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a,b=mi()
l=list(mi())
l=sorted(l)
c=0
for i in range(b):
  c+=l[i]
print(c)

Submission status: Accepted

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

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

newlist = sorted(li)
sum = 0
for i in range(K):
    sum = sum + newlist[i]
print(sum)

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())
a=input().split()
a1=[]
for i in range(len(a)):
  a1.append(int(a[i]))
S=0
for i in range(K):
  S+=min(a1)
  a1.remove(min(a1))
print(S)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq

n,k = map(int,input().split())
l1 = list(map(int,input().split()))
l2 = heapq.nsmallest(k, l1)
print(int(sum(l2)))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
count = 0
new_list = []
while count < K:
    min = P[0]
    for i in P:
        if min > i:
            min = i
    new_list.append(min)
    P.remove(min)
    count += 1
print(sum(new_list))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=[]
c=0

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

for j in range(0,k):
    c=c+a[j]
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
t, select = input().split()
prices = input().split()

price_list = []
for price in prices:
    price_list.append(int(price))
    
price_list.sort()
total = 0
for i in range(int(select)):
    total += price_list[i]
print(total)

Submission status: Accepted

Solution code:
a=[input() for i in range(2)]

a1=a[0]
p=a[1]

a1=[int(i) for i in a1.split()]
p=[int(i) for i in p.split()]

p_up=sorted(p)

sum=0

for i in range(a1[1]):
	sum+=p_up[i]

print(sum)

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())
c =0
l = list(map(int,input().split()))
l.sort()
for i in range (k):
    c += l[i]
print(c)

Submission status: Accepted

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

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

s = sorted(p)

ans = 0 
for i in range(N):
    ans += s[i]
    if i == K-1:
        break

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, K = input().split(' ')
    l = list(map(int, input().split(' ')))
    l.sort()
    sum = 0

    for i in range(int(K)):
        sum = sum + l[i]
    print(sum)

main()

Submission status: Accepted

Solution code:

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

print(sum(clist[0:K]))

Submission status: Accepted

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

price = 0
if N > 0:
    for j in range(K):
        price += p[j]
print(price)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
asr = sorted(a,reverse=True)
del asr[0:n-k]
ans = sum(asr)
print(str(ans))

Submission status: Accepted

Solution code:
n,k = 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 = list(map(int,input().split()))

P.sort()

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,k = inpm()
    a = inpl()
    ans = 0
    a.sort()
    for i in range(k):
        ans += a[i]
    print(ans)
    
if __name__ == "__main__":
    main()

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:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    print(sum((sorted(A)[0:K])))

if __name__ == "__main__":
    main()

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:
a,b = map(int, input().split()) 

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

list=sorted(num)
sum=0
for i in range(b):
    sum+=list[i]
print(sum)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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:
import numpy as np
s = list(map(int, input().split()))
n = list(map(int, input().split()))
sumn = 0

n.sort()
for i in range(s[1]):
  sumn += n[i]

print(sumn)

Submission status: Accepted

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

ls = list(map(int, input().split()))
ans = 0

ls2 = sorted(ls)

for i in range(K):
  ans += ls2[i]

print(ans)

Submission status: Accepted

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

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

P = sorted(P)

print(sum(P[:K]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n,k=NM()
l=L()
l.sort()
print(sum(l[:k]))

Submission status: Accepted

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

Submission status: Accepted

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

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

P_li.sort()

sum=0

for i, name in enumerate(P_li):
    if i < K:
        sum+=name
print(sum)

Submission status: Accepted

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

s = 0

for i in range(K):
    t = min(p)
    s = s + t
    p.remove(t)

print(s)

Submission status: Accepted

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

p.sort()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Ans = 0
for i in range(K):
    minp = min(p)
    p.remove(minp)
    Ans +=minp
print(Ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
try:
   n,k = map(int,input().split(" "))
   pi=list(map(int,input().split(" ")))
   pi.sort()
   cost=0
   i=0
   for i in range(k):
        cost+=pi[i]
   print(cost)
except:
    pass

Submission status: Accepted

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

N=NK[0]
K=NK[1]
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())
p = list(map(int, input().strip().split()))

small = sorted(p)

result = 0
for i in range(k):
    result += small[i]

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=input()
a=a.split()
K=int(a[1])

b=input()
b=b.split()
b=list(map(int, b))
b.sort()
z=0
n=0
for x in range(K):
  z=b[n]+z
  n=n+1
  
print(z)

Submission status: Accepted

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

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


if(__name__ == '__main__'):
  main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
num_list = list(map(int,input().split()))
sum = 0
smallest = 1000
smallest_i = 0
for j in range(k):
    smallest = 1000
    for v, i in enumerate(num_list):
        if i < smallest:
            smallest = i
            smallest_i = v
    sum += smallest
    num_list[smallest_i] = 1000

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
p = map(int,input().split())
newlist = sorted(p, reverse=False)
ans=[]
for i in range(1,K+1):
    ans.append(newlist[i-1])
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N, K = [int(i) for i in input().split()]
    A = sorted([int(i) for i in input().split()])
    sumA = 0
    for a in A[:K]:
        sumA += a
    print(sumA)


resolve()

Submission status: Accepted

Solution code:
#-*- using:utf-8 -*-
 
N, K = map(int, input().split())
p = sorted(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())
P=sorted(list(map(int,input().split())))
print(sum(P[0:K]))

Submission status: Accepted

Solution code:
(n,k) = input().split()
n = int(n)
k = int(k)
p = input().split()
p = [int(x) for x in p]
p.sort()
print(sum(p[0: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 python
import sys
import re
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def main():
    #N, M = map(int, input().split())
    N, K = map(int, input().split())
    ps = list(map(int, input().split()))

    ps = sorted(ps)

    print(sum(ps[:K]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

price=sorted(price)
alter_price = sorted(price)
ans = alter_price[:K]
answer=sum(ans)
print(answer)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K, *P = map(int, read().split())

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split(' '))
P = list(map(int,input().split(' ')))
if(K==1):
  print(min(P))
else:
  res=[]
  for i in range(K):
    res.append(min(P))
    P.remove(min(P))
  print(sum(res))

Submission status: Accepted

Solution code:
import heapq
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
print (sum(heapq.nsmallest(X[1], Y)))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
p=list(map(int,input().split()))
result=0
lst=sorted(p)
lst2=lst[:M]
print(sum(lst2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    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=(int(x) for x in input().split())
p = list(int(x) for x in input().split())

p.sort()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

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

prices = sorted(prices)

print(sum(prices[:k]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=input().split(" ")
b=input().split(" ")
c=[int(i) for i in b]
pay=sorted(c)
pay1=0

for i in range(int(a[1])):
    pay1=pay1+int(pay[i])

print(pay1)

Submission status: Accepted

Solution code:
n , x = map(int,input().split())
price_list = list(map(int,input().split()))
ld = sorted(price_list, reverse=False)
sum = 0
for i in range(x):
  sum += ld[i]
print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = input().split()
price = list(int(t) for t in input().split())
price_s = sorted(price)
total = sum(price_s[0:int(K)])
print(total)

Submission status: Accepted

Solution code:
class Bucket:
  def __init__(self, max_size):
    self.__max_size = max_size
    self.__busket = []
    self.__max = 0
    self.__busket_size = 0

  def add(self, price):
    if self.__busket_size < self.__max_size:
      self.__busket.append(price)
      self.__busket_size += 1
      self.__max = max(self.__max, price)
      return self

    if self.__max <= price:
      return self

    self.__busket.remove(self.__max)
    self.__busket.append(price)
    self.__max = max(self.__busket)

  def sum(self):
    return sum(self.__busket)

if __name__ == "__main__":
  n, k = map(int, input().split(' '))
  price_list = list(map(int, input().split(' ')))
  b = Bucket(k)
  for p in price_list:
    b.add(p)
  
  print(b.sum())

Submission status: Accepted

Solution code:
import numpy as np

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

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