๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Algorithm/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

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

1. ๋ฌธ์ œ ์„ค๋ช…

๋ฌธ์ œ ๋งํฌ

  • ์ž…๋ ฅ

d : ๋ถ€์„œ๋ณ„๋กœ ์‹ ์ฒญํ•œ ๊ธˆ์•ก์ด ๋“ค์–ด์žˆ์Œ

budget: ์˜ˆ์‚ฐ

  • ์ถœ๋ ฅ

์˜ˆ์‚ฐ ์•ˆ์—์„œ ์ง€์› ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€์˜ ์‚ฌ๋žŒ์˜ ์ˆ˜

2. ์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

| d | budget | result |

| ----------- | :----: | ------ |

| [1,3,2,5,4] | 9 | 3 |

| [2,2,3,3] | 10 | 4 |

3. ์ฝ”๋“œ

def solution(total, budget):
    answer = 0
    count = 0
    total.sort()
    for t in total:
        if budget - t >=0:
            budget-=t
            count+=1

    return count