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: Time Limit Exceeded

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

ans = float("inf")
for i in range(1 << len(P)):
    sum = 0
    cnt = 0
    for j in range(len(P)):
        if (i >> j) & 1 == 1:
            sum += P[j]
            cnt += 1
            if cnt == K:
                ans = min(ans, sum)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

minprice = sum(plist)
sumlist =[]
for v in itertools.permutations(plist, K):
  sumlist.append(sum(v))
print (min(sumlist))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
from itertools import chain
from itertools import combinations as comb
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np


def solve(N: int, K: int, p: "List[int]"):
    answer = min(map(sum, comb(p, K)))
    return answer

def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, K, p = map(int, line.split())
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    answer = solve(N, K, p)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N,K=list(map(int, input().split()))
P=list(map(int, input().split()))
ans=float('INF')
L=list(combinations(range(N),K))
for a in L:
    sums=0
    for i in range(K):
        sums+=P[a[i]]
    # print(sums)
    ans=min(ans,sums)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product, permutations, combinations
import math
N, K = map(int, input().split())
P = list(map(int, input().split()))

ans = math.inf
for pt in combinations(P, K):
    ans = min(ans, sum(pt))

print(ans)
exit()

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, k = map(int, input().split())
lst = [int(i) for i in input().split()]

lists = list(itertools.combinations(range(n), k))
#print(lists)
min_price = float('inf')
for each in lists:
  total = 0
  for index in each:
    total += lst[index]
  if total < min_price:
    min_price = total
print(min_price)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

l = list(combinations(p, K))

ans = []

for i in l:
    ans.append(sum(i))

print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = 1000*1000

for i in itertools.permutations(p_list,k):
    ans = min(ans, sum(i))

print(ans)

Submission status: Time Limit Exceeded

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

min_ = float('inf')
combi = itertools.combinations(p, k)
for c in combi:
    min_ = min(min_, sum(c))
    
print(min_)

Submission status: Time Limit Exceeded

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

buy = list(combinations(P, K))
sum_money = [sum(b) for b in buy]
print(min(sum_money))

Submission status: Time Limit Exceeded

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
import itertools
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N,K = MI()
P = LI()

X = list(itertools.combinations(P,K))

ans = 10**9
for x in X:
   ans = min(ans, sum(x))


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

total =[]

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

for i in itertools.combinations(p, K):
    total.append(sum(i))

print(min(total))

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
p=list(map(int,input().split()))
import itertools
l=list(itertools.combinations(p,K))
M=999999999999999999
for i in l:
    M=min(M,sum(i))
print(M)

Submission status: Time Limit Exceeded

Solution code:

import itertools
import numpy as np

tmp = input()
N,K = tmp.split()
que = input()
try:
    N = int(N)
except:
    pass
try:
    K = int(K)
except:
    pass



que = [int(x) for x in que.split()]

#print(que)
"""
tmp = []
for x in que:
    for xx in range(K):
        tmp.append(x)
que = tmp
"""
min_val = 999999999

for x in itertools.combinations(que, K):
    tmp = np.sum(x)
    if tmp < min_val:
        min_val = tmp

print(min_val)

Submission status: Time Limit Exceeded

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

i=0
while True:
    if len(p)==1:
        break
    if p[i]<=p[i+1]:
        i+=1
    else:
        a=p[i]
        p[i]=p[i+1]
        p[i+1]=a
        i=0
    if i==len(p)-1:
        break

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K,*p = map(int,open(0).read().split())
print(min(map(lambda x: sum(x),itertools.combinations(p,K))))

Submission status: Time Limit Exceeded

Solution code:
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 
import itertools

l=[]
for v in itertools.combinations(B, A[1]):
  l.append(sum(v))
  
print(min(l))

Submission status: Time Limit Exceeded

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

import itertools
lis = list(itertools.combinations(range(N), K))

mi = 0
for x in lis:
    cur = 0
    for pos in x:
        cur += p[pos]

    if mi == 0:
        mi = cur
    else:
        mi = min(mi, cur)

print(mi)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = map(int, input().split())
p = [int(n) for n in input().split()]
p = list(itertools.combinations(p, K))
min = 0
for i in range(K):
    min += p[0][i]
for i in range(len(p)):
    a = 0
    for j in range(K):
        a += p[i][j]
        if a > min:
            break
    if a < min:
        min = a
print(min)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = map(int, input().split())
p = [int(n) for n in input().split()]
p = list(itertools.combinations(p, K))
min = 0
for i in range(K):
    min += p[0][i]
for i in range(len(p)):
    a = 0
    for j in range(K):
        a += p[i][j]
    if a < min:
        min = a
print(min)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K=map(int,input().split())
onedan=list(map(int,input().split()))
sitei=[]
for v in itertools.permutations(onedan,K):
    sitei.append(sum(v))
print(min(sitei))

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
S = list(map(int, input().strip().split()))
N = S[0]
K = S[1]
p = list(map(int, input().strip().split()))
lists = [1000000000000]
for l in list(itertools.combinations(p, K)):
  sums = sum(list(l))
  if sums <= min(lists):
    lists.append(sums)

print(min(lists))

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
S = list(map(int, input().strip().split()))
N = S[0]
K = S[1]
p = list(map(int, input().strip().split()))
lists = [1000000000000]
for l in list(itertools.combinations(p, K)):
  sums = sum(list(l))
  if sums <= lists[0]:
    lists.append(sums)

print(min(lists))

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
S = list(map(int, input().strip().split()))
N = S[0]
K = S[1]
p = list(map(int, input().strip().split()))
lists = []
for l in list(itertools.combinations(p, K)):
  sums = sum(list(l))
  lists.append(sums)

print(min(lists))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
t = []
N, K = map(int, input().split())
p = [int(i) for i in input().split()]
a = list(itertools.permutations(range(N), K))
for i in range(len(a)):
    s = 0
    for j in range(K):
        s += (p[a[i][j]])
    t.append(s)
print(min(t))

Submission status: Time Limit Exceeded

Solution code:
import itertools
t = 10**5
N, K = map(int, input().split())
p = [int(i) for i in input().split()]
a = list(itertools.permutations(range(N), K))
for i in range(len(a)):
    s = 0
    for j in range(K):
        s += (p[a[i][j]])
    if t > s:
        t = s
print(t)

Submission status: Time Limit Exceeded

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

for i in range(2 ** N):
    bit = []
    total = 0
    
    for j in range(N):
        if ((i>>j) & 1):
            bit.append(p[j])
            total += p[j]
    if len(bit) == K:
        if sum(bit) < result:
            result = sum(bit)
print(result)

Submission status: Time Limit Exceeded

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

n_list=[]
for com in itertools.combinations(price,k):
    s=sum(com)
    n_list.append(s)
print(min(n_list))

Submission status: Time Limit Exceeded

Solution code:
import itertools
ans = 10000000000000000000000000000000000
n, k = map(int, input(). split())
p = list(map(int, input(). split()))
P = list(itertools.combinations(p, k))
s = len(P)
for i in range(s):
  P[i] = list(P[i])
  q = sum(P[i])
  if ans >= q:
    ans = q
print(ans)

Submission status: Time Limit Exceeded

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

cheap = []

for m in range(k):
    for i in range(len(l)):
        flag = False
        for j in range(len(l)):
            if l[i] > l[j]:
                flag = True
                break
        if flag == False:
            cheap.append(l[i])
            l.remove(l[i])
            break

print(sum(cheap))

Submission status: Time Limit Exceeded

Solution code:
import itertools
result = 10000000000000000000
N,K = map(int,input().split())
p = list(map(int,input().split()))
array = list(itertools.combinations(p,K))
#print(list(itertools.combinations(p,K)))

for i in array:
    if sum(i) < result:
        result = sum(i)
print(result)

Submission status: Time Limit Exceeded

Solution code:
import itertools
ans = 10000000000000000000000000000000000
n, k = map(int, input(). split())
p = list(map(int, input(). split()))
P = list(itertools.permutations(p, k))
s = len(P)
for i in range(s):
  P[i] = list(P[i])
  q = sum(P[i])
  if ans >= q:
    ans = q
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N, K = [int(x) for x in input().split()]
prices = [int(x) for x in input().split()]

min_value = 1000 * 1000
for x in combinations(prices, K):
  min_value = min(min_value, sum(x))

print(min_value)

Submission status: Time Limit Exceeded

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()
    c = itertools.combinations(p, K)
    clist = list(c)
    cn = len(clist)

    for i in range(cn):
        sumi = int(sum(clist[i]))
        if i == 0:
            min =sumi
        if min > sumi:
            min = sumi

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



if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N, K = map(int,input().split())
lists = combinations(range(N),K)
s = list(map(int,input().split()))
min_result = 1000000000000
for li in lists:
    total = 0
    for l in li:
        total += s[l]
    min_result = min(min_result,total)

print(min_result)

Submission status: Time Limit Exceeded

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

sum0 = 100100100

for i in itertools.combinations(p, k):
    sum1 = sum(i)
    if sum0 > sum1:
        sum0 = sum1
        
print(sum0)

Submission status: Time Limit Exceeded

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

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

for i in range(2**N):
  num = 0
  s = 0
  for j in range(N):
    if ((i >> j) & 1):
      if num < K:
        s += ls[j]
        num += 1
  if num == K:
    ans.append(s)

ans2 = sorted(ans)
print(ans2[0])

Submission status: Time Limit Exceeded

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

sum0 = 100100100

for i in itertools.permutations(p, k):
    sum1 = sum(i)
    if sum0 > sum1:
        sum0 = sum1
        
print(sum0)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N, K = list(map(int, input().split()))
p_n = list(map(int, input().split()))
ans = 10 ** 10

for p in itertools.combinations(p_n, K):
    s = sum(p)
    if ans > s:
        ans = s

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=[int(i) for i in input().split()]
P=[int(i) for i in input().split()]
minS=float('inf')
for i in range(2**N):
  cmb=bin(i)[2:]
  cmb=(('0'*N)+cmb)[-N:]
  cmb=[int(i) for i in cmb]
  if sum(cmb)!=K:
    continue
  s=sum([P[i]*cmb[i] for i in range(N)])
  if minS > s:
    minS=s
print(minS)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = map(int,input().split())
P = list(map(int,input().split()))
Sigmas = []
for M in itertools.combinations(P,K):
    Sigma = sum(list(M))
    Sigmas.append(Sigma)
print(min(Sigmas))

Submission status: Time Limit Exceeded

Solution code:

import itertools

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

kumi = list(itertools.combinations(list(range(n)), k))
answer = sum(data)

for comb in kumi:
    total = 0
    for x in comb:
        total += data[x]
    if total < answer:
        answer = total

print(answer)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans = 1000000

for i in itertools.permutations(prices, k):
    ans = min(ans, sum(i))

print(ans)

Submission status: Time Limit Exceeded

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

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

for i in range(2**N):
  num = 0
  s = 0
  for j in range(N):
    if ((i >> j) & 1):
      if num < K:
        s += ls[j]
        num += 1
  if num == K:
    ans.append(s)

print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N, K = list(map(int, input().split()))
p_n = list(map(int, input().split()))
ans = 10 ** 10

for p in itertools.permutations(p_n, K):
    s = sum(p)
    if ans > s:
        ans = s

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n,k = map(int,input().split())
list1 = list(map(int,input().split()))
list2  = []
for i in combinations(list1,k) :
    list2.append(sum(i))
print(min(list2))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans = 1000000

for i in itertools.combinations(prices, k):
    ans = min(ans, sum(i))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

  min_ = float('inf')

  all_ = list(range(N))
  for items in itertools.combinations(all_, K):
    sum_ = sum([P[i] for i in items])
    min_ = min(min_, sum_)

  print(min_)


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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans = 999999999

for i in itertools.combinations(prices, k):
    ans = min(ans, sum(i))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans = []
for v in itertools.combinations(p,K):
    ans.append(sum(v))
    
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans = 999999999999999

for i in itertools.combinations(prices, k):
    ans = min(ans, sum(i))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
n = len(p)
ans = 10 ** 9

for i in range(2 ** n):
    total = 0
    cnt = 0
    for j in range(n):
        if((i >> j) & 1):
            total += p[j]
            cnt += 1
    if cnt == K and ans > total:
        ans = total
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N, K = map(int,input().split())
lists = combinations(range(N),K)
s = list(map(int,input().split()))
min_result = 10 ** 9
for li in lists:
    total = 0
    for l in li:
        total += s[l]
    min_result = min(min_result,total)

print(min_result)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
from typing import Callable, NoReturn, Tuple


def main() -> NoReturn:
    readline: Callable[[], str] = sys.stdin.readline
    n, k = map(int, readline().rstrip().split())  # type: int,...
    p: Tuple[int] = tuple(int(_) for _ in readline().rstrip().split())

    if k < n // 2:
        answer: int = 10 ** 6
        for combinations in itertools.combinations(p, k):
            sum_of_comb: int = sum(combinations)
            if sum_of_comb < answer:
                answer = sum_of_comb
    else:
        not_chosen: int = 0
        for combinations in itertools.combinations(p, n - k):
            sum_of_comb: int = sum(combinations)
            if sum_of_comb > not_chosen:
                not_chosen = sum_of_comb
        answer: int = sum(p) - not_chosen

    print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

  max_ = float('inf')
  for bit in range(1 << N):
    sum_ = 0
    if not(bin(bit).count('1') == K):
      continue
    for i in range(N):
      mask = 1 << i
      if bit & mask:
        sum_ += P[i]

    max_ = min(max_, sum_)

  print(max_)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = map(int, input().split())
P = list(map(int, input().split()))
B = list(itertools.combinations(P, K))
ans = []
if N == 1:
    print(P[0])
    exit(0)
for b in B:
    ans.append(sum(b))
print(min(ans))

Submission status: Time Limit Exceeded

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

import itertools

comb = list(itertools.combinations(p, k))

ans = 100000000
for i in range(len(comb)):
    ans = min(ans, sum(comb[i]))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from io import StringIO
import unittest
from itertools import combinations

def resolve():
	n, k = map(int, input().split())
	seq = map(int, input().split())
	ans = float('inf')
	for r in combinations(seq, k):
		ans = min(ans, sum(r))
	print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
from typing import Callable, NoReturn, Tuple


def main() -> NoReturn:
    readline: Callable[[], str] = sys.stdin.readline
    n, k = map(int, readline().rstrip().split())  # type: int,...
    p: Tuple[int] = tuple(int(_) for _ in readline().rstrip().split())

    answer: int = 10 ** 6
    for combinations in itertools.combinations(p, k):
        sum_of_comb: int = sum(combinations)
        if sum_of_comb < answer:
            answer = sum_of_comb

    print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

ans = float('inf')
for t in combinations(range(n),k):
    res = 0
    for i in range(k):
        res+=P[t[i]]
    ans = min(res,ans)
    
print(ans)

Submission status: Time Limit Exceeded

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

res = 10**16
for t in combinations(range(N), K):
  res = min(res, sum([P[i] for i in t]))
print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K= map(int,input().split())
p = list(map(int, input().split()))
ans = 1000000
for i in itertools.combinations(p, K):
    s = sum(i)
    ans = min(ans, s)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N, K = map(int, input().split(' '))
fruit_prices = tuple(map(int, input().split(' ')))

min_price = sum(fruit_prices)

for comb in combinations(fruit_prices, K):
  min_price = min(sum(comb), min_price)

print(min_price)

Submission status: Time Limit Exceeded

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

import itertools

comb = list(itertools.combinations(p, k))

ans = 100000000000
for i in range(len(comb)):
    ans = min(ans, sum(comb[i]))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from itertools import combinations
n,k = map(int,input().split())
if n==1:
    print(int(input()))
else:
    lis = input().split()
    total =np.inf

    for i in combinations(lis,k):
        ml =0

        for a in i:

            ml += int(a)

        total = min(total,ml)


    print(total)

Submission status: Time Limit Exceeded

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

    A_list = [A for A in input().split()]
    A_list = list(map(int, A_list))

    import itertools
    p = itertools.permutations(A_list, K)
    ans = 100000000000
    for val in p :
        ans_new = sum(val)
        if ans_new < ans :
            ans = ans_new
        #print(val)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = map(int,input().split())
A = map(int,input().split())
t = list(list(itertools.combinations(A,K)))
ans = sum(t[0])
for i in t:
    ans = min(ans,sum(i))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for v in itertools.combinations(p, K):
    tmp = sum(v) 
    if ans > tmp:
        ans = tmp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
from typing import Callable, NoReturn, Tuple


def main() -> NoReturn:
    readline: Callable[[], str] = sys.stdin.readline
    n, k = map(int, readline().rstrip().split())  # type: int,...
    p: Tuple[int] = tuple(int(_) for _ in readline().rstrip().split())

    answer: int = min(tuple(sum(fruits) for fruits in itertools.combinations(p, k)))
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int, input().split())
P = [*map(int, input().split())]
# print(n,k)
# print(P)

ans = 1000000000
for i in range(1<<n):
    # print(bin(i))
    v = []
    for j in range(n):
        if i>>j & 1:
          v.append(P[j])
        if len(v) == k: break
    # print(v)
    if len(v) == k:
        ans = min(ans, sum(v))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for v in itertools.combinations(p, K):
    if ans > sum(v):
        ans = sum(v)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

com = list(combinations(p,k))
ans = list(map(sum,com))
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

# tmp = itertools.combinations_with_replacement(P, K)
tmp = itertools.combinations(P, K)

hoge = []
for i in tmp:
    hoge.append(sum(i))

print(min(hoge))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations as comb

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

min=None
for x in comb(range(n),k):
    sm=0
    for i in range(len(x)):
        sm+=p[x[i]]
    if not min : min=sm
    if sm<min : min=sm
print(min)

Submission status: Time Limit Exceeded

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

c = itertools.combinations(p, K)
ans = 10**10
for i in c:
    ans = min(ans, sum(i))
print(ans)

Submission status: Time Limit Exceeded

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

combi = list(itertools.combinations(p,k))
for i in range(len(combi)) :
    ans.append(sum(combi[i]))
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys

input = sys.stdin.readline

N, K = map(int, input().split())
p = list(map(int, input().split()))
l = [sum(i) for i in itertools.combinations(p, K)]
print(min(l))

Submission status: Time Limit Exceeded

Solution code:
# import sys
# input = sys.stdin.readline
# import re
import itertools

def main():
    n, k = input_list()
    p = input_list()

    pp = []
    for v in itertools.combinations(p, k):
        pp.append(sum(v))
    print(min(pp))

def count_tento(l, cur):
    count = 0
    for v in l:
        if v > cur:
            count += 1
    return count

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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for i in itertools.combinations(p, K):
    tmp = sum(list(i))
    if tmp < ans:
        ans = tmp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

ans = 100000000
for tup in combinations(P, K):
    price = sum(tup)
    ans = min(price,ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import itertools
    N, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    minA = 10**9
    for a in itertools.combinations(A, K):
        minA = min(minA, sum(a))
    print(minA)

resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
# list(map(int, input().split()))

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

from itertools import combinations

ans = 10 ** 12
for i in combinations(P, k):
    ans = min(ans, sum(i))
print(ans)

Submission status: Time Limit Exceeded

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

import itertools
c = itertools.combinations(p, K)
L = [sum(item) for item in c]
print(min(L))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = sum(p)
for v in itertools.permutations(p, K):
    ans = min(ans, sum(v))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n,k = map(int,input().split())
p = list(map(int,input().split()))
ans = 10**19

for i in itertools.permutations(p,k):
    s = sum(i)
    if s < ans:
        ans = s

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans = 9999999999

for i in itertools.combinations(prices, k):
    ans = min(ans, sum(i))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,K = mips()
ans = 10**9
P = [p for p in mips()]
L = list(map(list,itertools.permutations(P,K)))
for el in L:
    ans = min(ans,sum(el))
print(ans)

Submission status: Time Limit Exceeded

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 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 = readInts()
mi = float('inf')
for pa in combinations(A,k):
    nya = sum(pa)
    mi = min(mi,nya)
print(mi)