Skip to content

Commit 60b835b

Browse files
committed
111차 2번 문제풀이
1 parent 35d37d4 commit 60b835b

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
"""
2-
우선순위 큐 사용하고 개수와 마지막 종료 날짜 곱하면 되지 않을끼....
3-
"""
41
import sys
5-
import heapq
62

73
input = sys.stdin.readline
84

95
n = int(input())
10-
schedule = []
11-
heapq.heapify(schedule)
6+
years = [0] * 366
127
for _ in range(n):
138
s, e = map(int, input().split())
14-
heapq.heappush(schedule, (e, s))
9+
for i in range(s, e + 1):
10+
years[i] += 1
1511

16-
while schedule:
17-
heapq.heappop(schedule)
18-
if
12+
# [0, 0, 1, 1, 2, 3, 2, 2, 1, 1, 0, 1, 2, ...]
13+
14+
chunk = []
15+
group = []
16+
for i in range(1, len(years)):
17+
if years[i] != 0:
18+
chunk.append(years[i])
19+
else:
20+
if chunk:
21+
group.append(chunk[:])
22+
chunk.clear()
23+
if chunk:
24+
group.append(chunk[:])
25+
26+
res = 0
27+
for g in group:
28+
res += max(g) * len(g)
29+
30+
print(res)

0 commit comments

Comments
 (0)