practivceAlgorithm/백준

[백준][Python] 11256 사탕

findTheValue 2021. 9. 13. 02:43

내림차순 정렬

 

import sys
input = sys.stdin.readline

for _ in range(int(input())):
    J, N = map(int, input().split())
    cases = []
    for i in range(N):
        R, C = map(int, input().split())
        cases.append(R*C)
    cases.sort(reverse=True)
    cnt = 0
    for case in cases:
        J -= case
        cnt += 1
        if J <= 0:
            print(cnt)
            break