티스토리 뷰

728x90

https://www.acmicpc.net/problem/11256

 

11256번: 사탕

당신은 사탕 공장의 주인이다. 날마다, 당신은 J개의 사탕을 가게에 보내기 위해 상자에 포장해야 한다. 당신은 크기가 다른 상자 N개를 가지고 있다. 당신은 편리를 위해 상자를 최소한으로 쓰

www.acmicpc.net

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
= int(input())
for _ in range(t):
    j, n = map(int, input().split())
    lst = []
    for _ in range(n):
        r, c = map(int, input().split())
        lst.append(r * c)
    lst.sort(reverse=True)
    res = 0
    for i in lst:
        if j > i:
            j -= i
            res += 1
        else:
            break
    if j > 0:
        res += 1
    print(res)
cs
댓글