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:
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n,k = IL()
    p = list(IL())
    p.sort()
    ans = 0
    ans = sum(p[:k])
    print(ans)
    return

if __name__=='__main__':
    Main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

p_list = list(map(int, input().split()))
p_list.sort()

#print(p_list[:k])
print(sum(p_list[:k]))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = [int(x) for x 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())
ps   = sorted(map(int, input().split()))

print(sum(ps[:k]))

Submission status: Accepted

Solution code:
def run(n, k, num_array):
    '''
    '''
    print(sum([i for i in sorted(num_array)[:k]]))

if __name__ == '__main__':
    n, k = list(map(int, input().split()))
    num_array = list(map(int, input().split()))

    run(n, k, num_array)

Submission status: Accepted

Solution code:
N, K = list(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()))
p.sort()
add=0
for i in range(k):
    add+=p[i]
print(add)

Submission status: Accepted

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    k = kwargs["k"]
    P = kwargs["P"]
    P = sorted(P)
    res = sum(P[:k])
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"], kwargs["k"] = [int(i) for i in cin]
    cin = input().split()
    kwargs["P"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Submission status: Accepted

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

sort_p = sorted(p)
print(sum(sort_p[: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:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = [list(map(int, input().split()))]
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())
    n, k = map(int, input().split())
    p_s = list(map(int, input().split()))

    p_s.sort()

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



# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """5 3
50 100 80 120 80"""
        output = """210"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """1 1
1000"""
        output = """1000"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(cost)

Submission status: Accepted

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

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())
li = list(map(int,input().split()))
li.sort()
print(sum(li[: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:
# -*- coding: utf-8 -*-

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:
X = list(map(lambda x:int(x), input().split()))
n = X[0]
k = X[1]
p = list(map(lambda x:int(x), input().split()))

p.sort()

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
Ps = [int(p) for p in input().split() ]
Ps = sorted(Ps)
print(sum(Ps[: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:
#b
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:
a,b = map(int,input().split())
l = list(map(int,input().split()))
l.sort()

print(sum(l[0:b]))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

list.sort()

print(sum(list[:k]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import glob
import os

bn = os.path.basename(__file__).split('.')[0]
dn = os.path.dirname(__file__).split('/')

# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = dn[len(dn)-2] + '\\' + dn[len(dn)-1] + '\\' + bn

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

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

        p.sort()

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

        print(str(result))

solver = Solver(REL_PATH)
solver.exec_resolve()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(k):
    min_i = min(p_li)
    p_li.remove(min_i)
    ans += min_i

print(ans)

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

print(sum(list_[:k]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N, K = map(int, input().split())
P = sorted(list(map(int, input().split())))
print(sum(P[:K]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys

N,K = map(int,sys.stdin.readline().split())

a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
print(sum(sorted(a)[:K]))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(result)

Submission status: Accepted

Solution code:
def main():
    n, k = [int(v) for v in input().split()]
    p = sorted([int(v) for v in input().split()])
    q = sum(p[:k])
    print(q)

main()

Submission status: Accepted

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


p_list = sorted(p_list)

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

Submission status: Accepted

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

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:
data = input().rstrip().split(" ")
data2 = input().rstrip().split(" ")
price = []
for i in data2:
    price.append(int(i))
price.sort()
ans = 0
for i in range(int(data[1])):
    ans += price[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    import sys
    sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
    to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
    print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

    # 入力を整数に変換して受け取る
    def input_int(): return int(input())

    def map_int_input(): return map(int, input())

    MII = map_int_input

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

    def MII_to_index(): return map(to_index, input())

    def MII_split_to_index(): return map(to_index, input().split())

    # 入力全てを整数に変換したものの配列を受け取る
    def list_int_inputs(): return list(map(int, input()))

    LII = list_int_inputs

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

    # 2次元リスト化
    def LII_2D(rows_number): return [LII() for _ in range(rows_number)]

    def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)]

    N, K = MII_split()
    ps = LII_split()

    import numpy as np
    ps_array = np.array(ps)
    indicies = np.argsort(ps_array)
    print(sum([ps[i] for i in indicies[:K]]))
    
resolve()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p_list = list(map(int,input().split()))
p_list = sorted(p_list)
print(sum(p_list[: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())
li = list(map(int, input().split()))
li.sort()
ans = 0
for i in range(k):
    ans += li[i]
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:
n,k = map(int, input().split())
la = list(map(int, input().split()))
la.sort()
print(sum(la[0:k]))

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

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

print(price_sum)

Submission status: Accepted

Solution code:
from collections import deque

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

    p.sort()

    q = deque(p)

    ans = 0
    for _ in range(K):
        ans += q.popleft()

    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:
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 = int(input())
# s = input()

# # a = [int(i) for i in input().split()]

# if s.isupper():
#     print('A')
# else:
#     # print('a')

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

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

# print(p)

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=list(map(int,input().split()))
p=sorted(int(i) for i in p)
print(sum(p[0: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 = list(map(int, input().split()))
P = list(map(int, input().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_new = sorted(p)
price = 0
for i in range(k):
  price += p_new[i]
print(price)

Submission status: Accepted

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

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

print(sum(arr[:k]))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

p2 = sorted(p)

print(sum(p2[:k]))

Submission status: Accepted

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

print(sum(p_list[:k]))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
lis = list(map(int, input().split()))
lis = sorted(lis)
total = 0

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

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

given_list_sort = sorted(given_list)
temp_sum = 0
for i in range(K):
    temp_sum += given_list_sort[i]

print(temp_sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, K = map(int, input().split())
    P = list(map(int, input().split()))

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


main()

Submission status: Accepted

Solution code:

n,k = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()
#print(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 = list(map(int, input().split()))
p_list = sorted(p_list)

print(sum(p_list[: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:
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 = (int(x) for x in input().split())
p = [int(x) for x in input().split()]
p.sort()
print(sum(p[0:K]))

Submission status: Accepted

Solution code:
N, K = [int(i) for i in 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())
x = list(map(int, input().split()))
x.sort()
ans = 0
for i in range(K):
    ans = ans + x[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 = 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())
lst = list(map(int, input().split()))
lst.sort()
total = 0
for i in range(K):
    total += lst[i]
print(total)

Submission status: Accepted

Solution code:
import heapq
n,k=map(int,input().split())
p=list(map(int, input().split()))
heapq.heapify(p)
ans=0
for _ in range(k):
    tmp=heapq.heappop(p)
    ans+=tmp
print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

n,k = nm()
p = nl()
p = sorted(p)
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()))
p.sort()
cost = 0
for i in range(K):
    cost += p[i]
print(cost)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def q2():
    n, k = [int(i) for i in input().split(" ")]
    p = [int(i) for i in input().split(" ")]
    p.sort()

    sn = 0
    for i in range(0, k):
        sn += p[i]
    print(sn)


q2()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum(a[:m]))

Submission status: Accepted

Solution code:
nk = list(map(int, input().split()))
lp = list(map(int, input().split()))

lp.sort()

print(sum(lp[:nk[1]]))

Submission status: Accepted

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, k = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    P = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    P.sort()
    cnt=0

    for i in range(k):
        cnt += P[i]

    print(cnt)


resolve()

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N, K = getNM()
P = getList()
P.sort()
P = P[:K]
print(sum(P))

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:
# -*- coding: utf-8 -*-
from sys import stdin
input = stdin.readline
import numpy as np

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

p.sort()

print(np.array(p[:K]).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(e) for e in input().split()]
p = [int(e) for e in input().split()]

p.sort()

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

print(sum)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N, K = [int(i) for i in input().strip().split()]
    prices = sorted([int(i) for i in input().strip().split()])

    return sum(prices[:K])


if __name__ == "__main__":
    print(main())

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(list(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=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 = sum(p[0:K:])
print(ans)

Submission status: Accepted

Solution code:
def main():
    N,K=map(int,input().split())
    p=[int(x) for x in input().split()]
    p.sort()
    ans=0
    for n in range(K):
        ans+=p[n]
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().rstrip().rsplit())
prices = sorted(list(map(int, input().rstrip().rsplit())))

print(sum(prices[:K]))

Submission status: Accepted

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

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

print(sum(p_list[:K]))

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    n,k = list(map(int,sys.stdin.readline().split()))
    p = list(map(int,sys.stdin.readline().split()))
    p.sort()
    ans = 0
    for i in range(k):
        ans += p[i]
    print(ans)
    return 0

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

NK=np.array(input().split(" "),dtype=np.int64)
N=NK[0]
K=NK[1]

p=np.array(input().split(" "),dtype=np.int64)

sorted_p=np.sort(p)

L=sorted_p[:K]

print(sum(L))

Submission status: Accepted

Solution code:
import sys

N, K = map(int, sys.stdin.readline().strip().split())

P = list(map(int, sys.stdin.readline().strip().split()))

P.sort()

ans = sum(P[:K])
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(sum(l[0:k[1]]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, k = [int(e) for e in input().split()]
    P = [int(e) for e in input().split()]

    P.sort()

    print(sum(P[:k]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split(" "))
pL = sorted(list(map(int, input().split(" "))))

print(sum(pL[:k]))

Submission status: Accepted

Solution code:
nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]
a = [int(i) for i in input().split()]
a = sorted(a)
sum = 0
for i in range(m):
  sum += a[i]
print(sum)

Submission status: Accepted

Solution code:
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(x) for x in input().split()]
l = [int(x) for x in input().split()]
l.sort()
ans = 0
for i in range(K):
    ans += l[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

INF = 1<<30
dp = [[INF]*(N) for _ in [0]*(M+1)]
dp[0][0] = 0
dp[1][0] = A[0]

for i, a in enumerate(A):
    if i == 0:
        continue
    for k in range(M+1):
        dp[k][i] = min(dp[k][i-1], dp[k-1][i-1]+a)

print(min(dp[M]))

Submission status: Accepted

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

Submission status: Accepted

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

S = 0
for i in range(K):
    S += prices[i]
print(S)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

p.sort()

count = 0
ans = 0

for i in p:
    count += 1
    if count == k+1:
        break
    ans += i

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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