본문 바로가기
Beakjoon&프로그래머스/파이썬

[백준/파이썬] 11256번 사탕

by 현장 2022. 5. 8.

-Code

for _ in range(int(input())):
    j, n = map(int, input().split())
    box = []
    cnt = 0
    for _ in range(n):
        a, b = map(int, input().split())
        box.append(a * b)
    box.sort(reverse=True)
    for i in box:
        j -= i
        cnt += 1
        if j <= 0:
            print(cnt)
            break