알고리즘 문제풀이

백준 25496 장신구 명장 임스 Python 그리디 정렬 실버5

아크몽 2024. 3. 14. 13:56

 

# 25496 장신구 명장 임스 실5
p,n = map(int,input().split())
arr = list(map(int,input().split()))
arr.sort()
# print(arr)
i = 0
cnt = 0
while p < 200:
    p += arr[i]
    i += 1
    cnt += 1
    if i == n-1:
        break
print(cnt)

 

실수

틀렸습니다 . 50%

n-1으로 둠

# 25496 장신구 명장 임스 실5
p,n = map(int,input().split())
arr = list(map(int,input().split()))
arr.sort()
# print(arr)
i = 0
cnt = 0
while p < 200:
    p += arr[i]
    i += 1
    cnt += 1
    if i == n-1:
        break
print(cnt)