개발자 톡

연습문제 톡 금고털이

시간초과가 발생합니다.

등록일
2024-07-24 23:36:12
조회수
147
작성자
gltmdgjs
import sys
howmany=list(map(int,input().split(" ")))
totalweight=howmany[0]
nomjewel=howmany[1]
money=0
weightlist=[]
pricejewel=[]

for i in range(nomjewel):
    tellprice=list(map(int,input().split(" ")))
    weightlist.append(tellprice[0])
    pricejewel.append(tellprice[1])


while totalweight>0:
    a=max(pricejewel)
    b=pricejewel.index(max(pricejewel))
    c=weightlist[b]
    if totalweight>c:
        totalweight=totalweight-c
        money=money+(a*c)
        pricejewel.pop(b)
        weightlist.pop(b)
    else :
        money=money+totalweight*a
        totalweight=0

print(money)


시간초과가 발생합니다.... 문제를 풀기만 하면 되는줄 알았는데 아니네요 ㅠㅠ 어떻게 하면 시간이 줄어들까요..?

#금고털이

이 카테고리의 톡 더보기