ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

11047๋ฒˆ: ๋™์ „ 0

์ฒซ์งธ ์ค„์— N๊ณผ K๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N ≤ 10, 1 ≤ K ≤ 100,000,000) ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ๋™์ „์˜ ๊ฐ€์น˜ Ai๊ฐ€ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ Ai ≤ 1,000,000, A1 = 1, i ≥ 2์ธ ๊ฒฝ์šฐ์— Ai๋Š” Ai-1์˜ ๋ฐฐ์ˆ˜)

www.acmicpc.net

 

๋ฌธ์ œ ํ’€์ด

 ํŠน์ • ๊ธˆ์•ก K๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, ๋™์ „์œผ๋กœ ๋ณ€ํ™˜ํ•  ๊ฒฝ์šฐ ์ตœ์†Œํ•œ์˜ ๋™์ „์œผ๋กœ ๋‚˜ํƒ€๋‚ด๋Š” ๋™์ „์˜ ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋™์ „ ์ค‘ ๊ธˆ์•ก์ด ๊ฐ€์žฅ ํฐ ๋™์ „๋ถ€ํ„ฐ ์ˆœํšŒํ•˜๋ฉฐ, ํ˜„์žฌ ๊ธˆ์•ก์ธ K๋ณด๋‹ค ์ž‘๋‹ค๋ฉด `divmod`๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ชซ์€ ๋™์ „์˜ ์ˆ˜, ๋‚˜๋จธ์ง€๋Š” ์ž”๋ˆ์ด ๋˜๋ฏ€๋กœ ์ด๋ฅผ ๊ฐฑ์‹ ํ•˜๋ฉฐ ๋ฐ˜๋ณตํ•˜๋ฉด ๋œ๋‹ค.

 

์ฝ”๋“œ

from sys import stdin

if __name__ == '__main__':
    n, k = map(int, stdin.readline().split())
    type_of_coin = \
        [int(stdin.readline()) for _ in range(n)]
    answer = 0

    for coin in type_of_coin[::-1]:
        if k < coin:
            continue
        else:
            q, r = divmod(k, coin)

        answer += q
        if not r:
            break
        k = r

    print(answer)
728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€