Skip to content

Commit 68b0a1e

Browse files
committed
feat: 2월 1주차 발제 자료 업로드
1 parent 556126e commit 68b0a1e

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'''
2+
BOJ #19638. 센티와 마법의 뿅망치 (실버1)
3+
https://www.acmicpc.net/problem/19638
4+
유형: Priority Queue, Data Structure
5+
'''
6+
7+
# 과제 문제의 답은 PR 올리는 날에 함께 올라갈 예정입니다.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## 🚀2월 1주차 (2/3) 스터디 발제 주제: Dynamic Programming - Tree
2+
> 발제자: 김민정 (@Mingguriguri)
3+
4+
> 주제: Priority Queue
5+
### 🗂️ 스터디 자료
6+
- PDF: [바로가기
7+
](./Study_BOJ_1202.pdf)
8+
9+
### 📖 문제
10+
- [백준 #1202. 보석 도둑](https://www.acmicpc.net/problem/1202): Priority Queue, 자료구조 / 골드2
11+
- 정답 코드: [Study_BOJ_1202_보석도둑.py](./Study_BOJ_1202_보석도둑.py)
12+
13+
### 💻 과제
14+
- [백준 #19638. 센티와 마법의 뿅망치](https://www.acmicpc.net/problem/19638): Priority Queue, 자료구조 / 실버1
15+
- 정답 코드: [Assignment_BOJ_19638_센티와마법의뿅망치.py](./Assignment_BOJ_19638_센티와마법의뿅망치.py)
579 KB
Binary file not shown.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'''
2+
BOJ #1202. 보석 도둑(골드2)
3+
https://www.acmicpc.net/problem/1202
4+
유형: Priority Queue, Data Structure, Greedy
5+
'''
6+
import sys
7+
import heapq
8+
9+
input = sys.stdin.readline
10+
11+
# Step 1: 입력 받기
12+
N, K = map(int, input().split()) # N: 보석 개수, K: 가방 개수
13+
jewelry = [] # (무게, 가격)
14+
bags = [] # 가방의 최대 무게
15+
16+
for _ in range(N):
17+
M, V = map(int, input().split())
18+
jewelry.append((M, V))
19+
20+
for _ in range(K):
21+
bags.append(int(input()))
22+
23+
# Step 2: 보석과 가방 정렬
24+
jewelry.sort() # 보석을 무게 기준으로 정렬
25+
bags.sort() # 가방을 무게 기준으로 정렬
26+
27+
# Step 3: 우선순위 큐 (최대 힙) 사용
28+
max_heap = []
29+
result = 0
30+
idx = 0
31+
32+
# 가방을 하나씩 처리
33+
for bag in bags:
34+
# 현재 가방이 수용할 수 있는 보석을 모두 추가 (무게 기준 정렬된 상태)
35+
while idx < N and jewelry[idx][0] <= bag:
36+
heapq.heappush(max_heap, -jewelry[idx][1]) # 최대 힙을 위해 음수 저장
37+
idx += 1
38+
39+
# 가장 가치가 높은 보석을 선택
40+
if max_heap:
41+
result += -heapq.heappop(max_heap)
42+
43+
print(result)
44+

0 commit comments

Comments
 (0)