금고 털이
Softeer - 현대자동차그룹 SW인재확보플랫폼
softeer.ai
- 내 풀이
- knapsack 문제인줄 알았으나 잘라서 넣을 수 있음 => 그리디
import sys
import heapq
input=sys.stdin.readline
w,n=map(int,input().split())
jewlery=[]
answer=0
for _ in range(n):
m,p=map(int,input().split())
heapq.heappush(jewlery, (-p,m))
while w>0:
price,weight=heapq.heappop(jewlery)
tmp=min(weight,w)
answer+=tmp*(-price)
w-=tmp
if w==0:
break
print(answer)
'코딩테스트 > SWEA' 카테고리의 다른 글
| [프로그래머스] 시소 짝꿍 (0) | 2025.03.24 |
|---|---|
| [소프티어][이분탐색][최장증가수열] 징검다리 (2) | 2025.02.06 |
| [소프티어][누적합] 성적 평균, 실전 문제 (0) | 2025.02.06 |
| [SWEA] 2105. 디저트 카페 (0) | 2023.05.22 |
| [SWEA] [부분집합] [백트래킹] 5215. 햄버거 다이어트 (0) | 2023.04.10 |