Skip to content

Commit e764be5

Browse files
Merge pull request #713 from gmlrude/main
[박희경] 111차 라이브 코테 제출
2 parents 63af82a + 60b835b commit e764be5

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
내가 생각한건 거리 * 사람수로 해서 구해보려했으나
3+
사람 수의 절반이 넘어가는 지점의 마을 위치를 찾는 문제 (그리디였음)
4+
"""
5+
import sys
6+
7+
input = sys.stdin.readline
8+
9+
n = int(input())
10+
village = []
11+
for _ in range(n):
12+
village.append(list(map(int, input().split())))
13+
14+
village.sort(key = lambda x: x[0])
15+
total = sum(p for _, p in village)
16+
17+
count = 0
18+
for position, people in village:
19+
count += people
20+
if count >= total / 2:
21+
print(position)
22+
break
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
3+
input = sys.stdin.readline
4+
5+
n = int(input())
6+
years = [0] * 366
7+
for _ in range(n):
8+
s, e = map(int, input().split())
9+
for i in range(s, e + 1):
10+
years[i] += 1
11+
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)