-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2294.py
More file actions
33 lines (25 loc) · 724 Bytes
/
2294.py
File metadata and controls
33 lines (25 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 동전 2
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10*6)
n, k = map(int, input().split())
coins = []
visited = [False]*(k+1)
for _ in range(n):
coins.append(int(input()))
coins.sort(reverse=True)
def minimumCoin(coins, limit):
collect = deque()
for coin in coins:
collect.append([1, coin])
while collect:
count, total = collect.popleft()
if total == limit:
return count
for coin in coins:
if (total + coin <= limit) and visited[total + coin] == False:
visited[total+coin] = True
collect.append([count+1, total + coin])
return -1
print(minimumCoin(coins, k))