성우리뷰
[Softeer] 금고 관리
두원공대88학번뚜뚜
2023. 3. 27. 10:44
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() 처리를 해줘야 정답이 됨.
난 이런식으로 알고리즘으로 승부보지 않고 얄팍한 상술로 봐야되는거 극혐한다.