import sys
input = sys.stdin.readline
from itertools import permutations
# λ μΌμ μμλ₯Ό μ‘°μν΄μ μ΅μνμ 무κ²λ§ λ€ μ μκ² νμ
n,m,k = map(int,input().split())
# n : λ μΌ / m : νλ°° λ¬΄κ² / k : μν νμ
result = 100000 # μ΅μ무κ²
rail = list(map(int,input().split()))
rail_list = list(permutations(rail)) # μμ΄
def cal(current):
total_weight, weight = 0, current[0]
idx, cnt = 0, 0
while cnt < k:
next_weight = current[(idx+1)%n]
if weight + next_weight > m:
total_weight += weight
weight = next_weight
cnt += 1
else:
weight += next_weight
idx += 1
return total_weight
for x in rail_list:
result = min(result,cal(x))
print(result)
μμ΄(Permutation)
permutations(λ°°μ΄, λ½λ κ°μ)
from itertools import permutations
a = [1,2,3,4]
res = permutations(a, 2)
print(list(res)) # listμ κ°μ΄ μ¨μΌ κ²°κ³Όλ₯Ό λ³Ό μ μλ€.
'Algorithm > Softeer' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Softeer - level2] 8λ¨ λ³μκΈ° (0) | 2023.07.25 |
---|---|
[Softeer - level3] μ€λ§νΈ λ¬Όλ₯ (0) | 2023.07.24 |
[Softeer - level2] [21λ μ¬μ§μ λν μμ ] λΉλ° λ©λ΄ (0) | 2023.07.23 |
[Softeer - level2] GBC (0) | 2023.07.23 |
[Softeer - level2] [21λ μ¬μ§μ λν μμ ] μ κ΄ν (0) | 2023.07.23 |