์˜ˆ์‚ฐ - ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

๋ฌธ์ œ

์˜ˆ์‚ฐ - Summer/Winter Coding(~2018)

ํ•ด์„ค

  1. ์ข‹์€ ๊ทธ๋ฆฌ๋”” ๋ฌธ์ œ์ด๋‹ค. ๋…ผ๋ฆฌ์ ์œผ๋กœ ์™œ ์ด๋ ‡๊ฒŒ ๋˜๋Š”์ง€ ์ƒ๊ฐํ•ด๋‚ด๋Š”๊ฒŒ ํฌ์ธํŠธ
  2. ํ•ด๋‹น ์‹œ์ ์—์„œ ๋๋‚  ๋•Œ, ์กฐ๊ฑด์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” if๋ฌธ์€ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋กœ ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ ์ข‹๊ณ , ์ด๊ฑธ while๋ฌธ์ฒ˜๋Ÿผ ๋ฉ”์ธ์œผ๋กœ ์‚ฌ์šฉํ•˜๋ฉด ์นด์šดํŠธ ์ฒ˜๋ฆฌํ•˜๋Š”๊ฒŒ ๋ณต์žกํ•ด์ง€๋‹ˆ ๊ทธ๋Ÿฐ๊ฑด ์ง€์–‘ํ•˜์ž.

ํ’€์ด

def solution(d, budget):
    s, cnt = 0, 0
    d.sort()
    for i in d:
        s += i
        if s > budget: 
            return cnt
        cnt += 1
    return cnt