-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnamhyun_0228.py
More file actions
57 lines (38 loc) · 964 Bytes
/
namhyun_0228.py
File metadata and controls
57 lines (38 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 1715 카드 정렬하기
import heapq
n = int(input())
card = []
for i in range(n):
card.append(int(input()))
heapq.heapify(card)
answer = 0
for i in range(n-1):
a = heapq.heappop(card)
b = heapq.heappop(card)
answer += a + b
heapq.heappush(card, a + b)
print(answer)
# 11000 강의실 배정
import heapq
n = int(input())
lst = []
for i in range(n):
s, t = map(int, input().split())
lst.append((s, t))
lst.sort() # 먼저 시작하는 강의부터 강의실 배정해야 하니 시작 시간을 기준으로 정렬.
heap = []
for i in range(n):
if not heap:
heapq.heappush(heap, lst[i][1])
elif lst[i][0] < heap[0]:
heapq.heappush(heap, lst[i][1])
else:
heapq.heappop(heap)
heapq.heappush(heap, lst[i][1])
#print(heap)
print(len(heap))
## 반례 (heap에 튜플 전체를 넣는 경우 틀리는 이유)
3
2 3
3 5
1 4