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())
p=list(map(int,input().split()))
print(sum(sorted(p)[:k]))

Submission status: Accepted

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

l.sort()
total = 0
for a in range(K):
  total += l[a]

print(total)

Submission status: Accepted

Solution code:
def main():
	n,m = map(int,input().split())
	l = list(map(int,input().split()))
	 
	l.sort()
	 
	print(sum(l[:m]))

if __name__ == '__main__':
	main()

Submission status: Accepted

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

l.sort()

print(sum(l[:K]))

Submission status: Accepted

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

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:
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########

def resolve():
    n,k = mi()
    p = mi()

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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())
price = list(map(int,input().split()))
price.sort()
print(sum(price[:k]))

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(K):
  ans += p[i]

print(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()
sum=0
for i in range(K):
	sum+=p[i]
print(sum)

Submission status: Accepted

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

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

p.sort()

print(sum(p[:k]))

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
A = list(map(int,input().split()))
#print(N,K,A[0],A[4])
value = 0
for i in range(K):
  value += min(A)
  A.remove(min(A))
print(value)

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()))
PS = sorted(P)
ans=0

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

print (ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[ ]:


#171B
#Mix Juice

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

Submission status: Accepted

Solution code:
mod = int(1e9+7)
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    #A, B = [int(x) for x in raw_input().split()]
    n, k = [int(x) for x in raw_input().split()]
    
    arr = [int(x) for x in raw_input().split()]
    
    arr.sort()
    
    ans = sum(arr[0:k])
    
    print(ans)
        
    

main()

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

ans=0
if n!=1:
    for i in range(k):
        min=p[i]
        for j in range(i+1,n):
            if min>p[j]:
                min=p[j]
                p[j]=p[i]
                p[i]=min
        ans+=min
else:
    ans=p[0]
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import io
import sys
import math

def solve(n,k,p_lst):
    pp_lst = sorted(p_lst)
    return sum(pp_lst[0:k])

def main():
    n,k = map(int, input().split())
    p_lst = list(map(int, input().split()))
    
    ans = str(solve(n,k,p_lst))
    print(ans)

    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
5 4
50 100 80 120 80
"""
_EXPECTED = """\
210
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Submission status: Accepted

Solution code:
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
print(sum(sorted(a)[:k]))

Submission status: Accepted

Solution code:
list1=(input().split())
list2=(input().split())
list3=[]
sum=0
for i in range(len(list2)):
  list3.append(int(list2[i]))
  list3.sort()
for j in range(int(list1[1])):
  sum=sum+list3[j]
print(sum)

Submission status: Accepted

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

# B - Mix Juice
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()
x=0
a=0
for x in range(k):
    a+=p[x]
    x+=1
print(a)

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 = list(map(int,input().split()))
p = sorted(p)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

p = np.sort(np.array(p))
print(sum(p[:K]))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
nsel = int(input().split()[1])
fruits = [int(fr) for fr in input().split()]
print(sum(sorted(fruits)[:nsel]))

Submission status: Accepted

Solution code:
K =  int(input().split()[1])
p = [int(n) for n in input().split()]
p.sort()
answer = 0
for i in range(K):
  answer += p[i]
print(answer)

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:
import sys
import math
import collections

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


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


def get(s):
    return str(s % 9) + '9' * (s // 9)

if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        n, k = int_input()
        A = int_input()

        A.sort()

        print(sum(A[:k]))

Submission status: Accepted

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

Submission status: Accepted

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

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())
A = list(map(int, input().split()))
A.sort()
print(sum(A[:k]))

Submission status: Accepted

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

    p = sorted(p)
    sum = 0
    for i in range(K):
        sum += p[i]

    print(sum)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,k = readInts()
A = sorted(readInts())
print(sum(A[:k]))

Submission status: Accepted

Solution code:
n, k = [int(e) for e in input().split()]
nums = [int(f) for f in input().split()]

nums.sort()

sum = 0
for i in range(k):
    sum += nums[i]
    
print(sum)

Submission status: Accepted

Solution code:
K = int(input().split(" ")[1])
p = [int(i) for i in input().split(" ")]
p.sort()
sum = 0
for i in range(K):
  sum += int(p[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[:k]))

Submission status: Accepted

Solution code:
N_K_var = input().split()
price_list_var = input().split()

N_K = [int(s) for s in N_K_var]
price_list = [int(s) for s in price_list_var]

price_sorted = sorted(price_list)
price = 0
for i in range(N_K[1]):
    price += price_sorted[i]

print(price)

Submission status: Accepted

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

for i in range(len(prices)):
    prices[i] = int(prices[i])

pricesSum = 0
while K > 0:
    newFruit = min(prices) 
    index = prices.index(newFruit)
    prices.pop(index)
    pricesSum += newFruit
    K -= 1
    
print(pricesSum)

Submission status: Accepted

Solution code:
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

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


yes = "Yes"
no = "No"


def main():
    n,k = mi()
    p = li()
    p.sort()
    ans = 0
    for i in range(k):
        ans+=p[i]
    print(ans)


main()

Submission status: Accepted

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

count = 0
for i in range(int(K)):
    count += A[i]
print(count)

Submission status: Accepted

Solution code:
import sys

data = sys.stdin

conversion_data = []
for l in data:
    conversion_data.append([int(i) for i in l.split()])
    

N = conversion_data[0][0]
K = conversion_data[0][1]
conversion_data[1].sort()
price_list = conversion_data[1]

print(sum(price_list[:K]))

Submission status: Accepted

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

p=sorted(p)
sum=0

for i in range(k):
    sum+=p[i]
print("{}".format(sum))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
gcd = math.gcd
n,k = ma()
P = list(ma())
P.sort()
print(sum(P[0:k]))

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, k = map(int, input().split())
p = [int(x) for x in input().split()]

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

Submission status: Accepted

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

new_p = sorted(prices)
sum = 0
for i in range(k):
    sum += new_p[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[:k]))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    P = [int(x) for x in input().split()]
    P.sort()

    print(sum(P[:K]))





if __name__ == '__main__':
    main()

Submission status: Accepted

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

y = sum(sorted(l)[:int(K)])

print(y)

Submission status: Accepted

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

p.sort()
#print(p)

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

print(ans)

Submission status: Accepted

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

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:
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
OutV = lambda x: print(*x, sep='\n')
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

N, K = iInM()
P = iInLH()

P.sort()

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
A=stdin.readline().split()
N=int(A[0])
K=int(A[1])
B=list(map(int,stdin.readline().split()))
B.sort()
sum=0

for k in range(0,K):
  sum+=B[k]
 
print(sum)

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:
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()))
m=list(map(int,input().split()))
m.sort()
print(sum(m[:k]))

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] = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()

import numpy as np
ans = np.sum(p[:K])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
p = sorted([int(i) for i in input().split()])
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 = ans + p[i]
print(ans)

Submission status: Accepted

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

count = 0
result = []
while count < a[1]:
  result.append(min(b))
  b.remove(min(b))
  count += 1
  
print(sum(result))

Submission status: Accepted

Solution code:
load = input().split(" ")
N = int(load[0])
K = int(load[1])

price = input().split(" ")
for i in range(len(price)):
  price[i] = int(price[i])

price.sort()

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

Submission status: Accepted

Solution code:
import sys

n, k = [int(x) for x in sys.stdin.readline().strip().split(" ")]
p = [int(x) for x in sys.stdin.readline().strip().split(" ")]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = input().strip().split()
n, k = [int(n), int(k)]

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

p.sort()

print(f'{sum(p[0:k])}')

Submission status: Accepted

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

N = int(inputs[0].split()[0])
K = int(inputs[0].split()[1])
p = [int(pn) for pn in inputs[1].split()]

ans = sum(sorted(p)[0:K])
print(ans)

Submission status: Accepted

Solution code:
li = input().split(' ')
N = int(li[0])
K = int(li[1])
li = input().split(' ')
li2 = []

for item in li:
  li2.append(int(item))
  
li2.sort()

print(sum(li2[:K]))

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())
p = list(map(int, input().split()))

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

Submission status: Accepted

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

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

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

a = 0

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

print(a)

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

p = sorted(p)
print(sum(p[:K]))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

def main():
    mod=10**9+7
    N,K=MI()
    p=LI()
    p.sort()
    ans=sum(p[:K])
    print(ans)

main()

Submission status: Accepted

Solution code:
# Problem B - Mix Juice

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

# initialization
p_nums = sorted(p_nums)
num_tmp = p_nums[:K]
ans = sum(num_tmp)

# output
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from queue import LifoQueue


def print_sol(c, sol):
    print('Case #{}: {}'.format(c, sol))


def rd_int():
    return int(input())


def rd_str():
    return input()


def rd_str_lst():
    return input().split(' ')


def sp_str_lst():
    return list(input())


def rd_int_lst():
    return [int(i) for i in rd_str_lst()]


def sp_int_lst():
    return [int(i) for i in sp_str_lst()]


def dfs(g, i, v):
    """
    recursive post order dfs
    Args:
        g: array of graph nodes
        i: node to traverse
        v: visited array

    Returns: a post order dfs of graph g
    """
    v[i] = True
    for j in g[i]:
        if not v[j]:
            dfs(g, j, v)

    print(i)


def dfs_iter(g, i, n):
    v = [False] * n
    stack = LifoQueue()
    stack.put(i)
    while stack.not_empty:
        u = stack.get()
        v[u] = True
        print(u)
        for i in g[u]:
            if not v[i]:
                stack.put(i)


def main():
    n, k = rd_int_lst()
    p = rd_int_lst()
    p.sort()

    print(sum(p[:k]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k  = [int(num) for num in input().strip().split(' ')]
prices = [ int(num) for num in input().strip().split(' ')]
prices.sort()
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, k = map(int, input().split())
    P = list(map(int, input().split()))
    P.sort()
    print(sum(P[:k]))
resolve()

Submission status: Accepted

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

prices = sorted(prices)


print(sum(prices[:K]))

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
fruits = list(map(int,input().split()))
total = 0

for i in range(k) :
    x = min(fruits)
    total += x
    fruits.remove(x)
    
print(total)

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([int(x) for x in input().split()])

print(sum(p[:K]))

Submission status: Accepted

Solution code:
from sys import stdin,stdout
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
import math
def p(a):print(" ".join(list(map(str,a))))
from collections import Counter

n,k=MAP()
a=sorted(LI())
print(sum(a[:k]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
arr = list(map(int, input().split()))
N = arr[0]
K = arr[1]

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

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:
from sys import stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
P = sorted([int(_) for _ in stdin.readline().rstrip().split()])
print(sum(P[:K]))

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

price = 0
for i in p[:k]:
    price = price + i
print(price)

Submission status: Accepted

Solution code:
import math
import sys
#####sorting a dictionary by the values#####
def dict_sort(ans):
    ans=sorted(ans.items(),reverse=True,key=lambda kv:(kv[1]))
#####Primes till Nth#####
def seive_primes(n):
    flag=[0]*(n+10)
    flag[1]=flag[0]=1
    i=2
    while i*i<=n+1:
        if flag[i]==0:
            j=i*i
            while j<=n+1:
                flag[j]=1
                j+=i
        i+=1
    return flag
##### naive method for testing prime or not#####
def is_prime(n):
    if n==1:
        return 0
    for i in range(2,int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True
#####greatest common divisor of two numbers#####
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
#####least common multiplyer of two numbers#####
def lcm(a,b):
    return (a*b)//gcd(a,b)
#####function that return all the letters#####
def alphbates():
    return "abcdefghijklmnopqrstuvwxyz"
#####taking an array/list as input#####
def inp():
    ls=list(map(int,input().split()))
    return ls
#####taking multiple inputs#####
def mult_inp():
    return map(int,input().split())
#####Main function starts from here#####
n,k=mult_inp()
ls=inp()
ls.sort()
print(sum(ls[:k]))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
L=list(map(int,input().split()))
L.sort()
print(sum(L[:k]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def addAndDeleteMin():
	global ans
	global p
	minv = min(p)
	ans += minv
	p.remove(minv)

n,k = map(int,input().split())
p = [int(x) for x in input().split()]
ans = 0
for i in range(k):
	addAndDeleteMin()
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    *p, = map(int, input().split())
    p.sort()
    print(sum(p[0:K]))
    return


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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 += l[i]
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
S=[0]*(N+1);w=0
P=list(map(int,input().split()))
for i in range(1,N+1):
  S[i-1]=[i,P[i-1]]
S[-1]=[0,1000]
S.sort(key=lambda x: x[1])
#print(S)
for i in range(K):
  w=w+S[i][1]
print(w)

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 = sorted(map(int,input().split()))
print(sum(P[:k]))

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