import sys
# 70*2 + 30*1 = 170, 자를 수 있다. 따라서 챙길 수 있는 것중 가장 비싼건 무조건 챙겨야됨.
input = sys.stdin.readline
wgt, cnt = map(int, input().split())
lst = []
lst = [list(map(int, input().split())) for _ in range(cnt)]
# for i in range(cnt):
# much, price = map(int, input().split())
# lst.append((price, much))
lst.sort(key = lambda x : x[1], reverse=True)
posb, curprice, idx = wgt,0, 0
while posb > 0:
if posb > lst[idx][0] :
curprice += lst[idx][1] * lst[idx][0]
else :
curprice += posb * lst[idx][1] # 챙길 수 있을만큼 챙기기
posb = posb - lst[idx][0] # 현재 다 챙기면 남는 가방무게
idx += 1
print(curprice)
지금 나랑 장난 똥때리나???
list 삽입에 있어 주석처리한 것을 내면 타임초과가 뜨고,
무조건
input = sys.stdin.readline
wgt, cnt = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(cnt)]
lst.sort(key = lambda x : x[1], reverse=True)
이런 식으로 sys.stdin.readline() 처리를 해줘야 정답이 됨.
난 이런식으로 알고리즘으로 승부보지 않고 얄팍한 상술로 봐야되는거 극혐한다.
'성우리뷰' 카테고리의 다른 글
[프로그래머스] 둘만의 암호 (0) | 2023.04.08 |
---|---|
[softeer] 성적평가 (0) | 2023.04.03 |
현대 이미지 프로세싱 (0) | 2022.03.22 |
현대 좌석관리 (0) | 2022.03.10 |
start, end 이중점 이용 마이크로서비스 (0) | 2022.03.05 |