1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import sys
t=int(sys.stdin.readline())
for _ in range(t):
j,n=map(int, sys.stdin.readline().split())
tmp=[]
for a in range(n):
r,c=map(int, sys.stdin.readline().split())
tmp.append(r*c)
tmp.sort()
tmp.reverse()
# print(tmp)
cnt=1
tmpCandy=0
for k in tmp:
tmpCandy+=k
# print(tmpCandy)
if tmpCandy<j :
cnt+=1
else:
print(cnt)
break
|
cs |
결국 큰 상자부터 써야되는게 핵심입니다
r*c의 곱을 내림차순 해서 앞에서부터 쓰는 방식으로 구현함
반응형
'python-algorithm' 카테고리의 다른 글
백준 16435 스네이크버드 (0) | 2021.08.26 |
---|---|
백준 14469 소가 길을 건너간 이유 3 (0) | 2021.08.26 |
백준 9237 이장님 초대 (0) | 2021.08.26 |
Leetcode 1877. Minimize Maximum Pair Sum in Array (0) | 2021.08.26 |
Leetcode 561. Array Partition I (0) | 2021.08.26 |
댓글