[Softeer 연습문제] Lv2. 금고털이
문제확인 : https://softeer.ai/practice/6288
Softeer - 현대자동차그룹 SW인재확보플랫폼
softeer.ai
💡 정답
import sys
W, N = map(int, sys.stdin.readline().split()) # 배낭의 무게 / 귀금속 종류
jewels = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
jewels.sort(reverse=True, key=lambda x: x[1]) # 가격(x[1]을 기준으로 내림차순 정렬
result = 0 # 최고 가격 저장할 변수
for M, P in jewels:
if W - M >= 0:
W -= M
result += (M * P)
else: # 잘라서
result += (W * P)
break
print(result)
'Coding Test > Softeer' 카테고리의 다른 글
[Softeer 연습문제] Lv2. 바이러스 (python) (0) | 2025.02.07 |
---|---|
[Softeer 연습문제] Lv2. 연탄의 크기 (python) (1) | 2025.02.07 |
[Softeer 연습문제] Lv2. GBC (python) (0) | 2025.02.07 |
[Softeer 연습문제] Lv3. 성적 평균 (python) (2) | 2025.02.07 |
[Softeer 연습문제] Lv2. GPT식 숫자 비교 (python) (0) | 2025.02.07 |