Skip to content

Commit 8f2cf3f

Browse files
authored
Merge pull request #90 from AlgorithmStudy-Allumbus/minjeong
Minjeong / 11์›” 3์ฃผ์ฐจ / 5๋ฌธ์ œ
2 parents 511fcd8 + 298c832 commit 8f2cf3f

5 files changed

+96
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
from collections import deque
3+
input = sys.stdin.readline
4+
5+
t = int(input())
6+
for _ in range(t):
7+
n = int(input()) # ๊ฑฐ์Šค๋ฆ„๋ˆ ์•ก์ˆ˜
8+
alphabet = list(map(str, input().split()))
9+
alphabet = deque(alphabet)
10+
answer = alphabet.popleft() # ์ •๋‹ต ๋ฌธ์ž์—ด
11+
12+
while alphabet:
13+
current = alphabet.popleft()
14+
if current <= answer[0]: # ๊ฐ€์žฅ ์•ž์˜ ๋ฌธ์ž์™€ ๋น„๊ต. ๋” ์•ž์— ์žˆ๋‹ค๋ฉด ๊ฐ€์žฅ ์™ผ์ชฝ์— ๋ถ™์ด๊ธฐ
15+
answer = current + answer
16+
else:
17+
# ๋’ค์— ์žˆ๋‹ค๋ฉด ๊ฐ€์žฅ ์˜ค๋ฅธ์ชฝ์— ๋ถ™์ด๊ธฐ
18+
answer += current
19+
20+
print(answer)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ์ž…๋ ฅ ์˜ˆ์‹œ: N๊ณผ ๊ฐ ๋ ˆ๋ฒจ ์ ์ˆ˜ ๋ฆฌ์ŠคํŠธ
2+
N = int(input())
3+
scores = [int(input()) for _ in range(N)]
4+
5+
# ๊ฐ์†Œ ํšŸ์ˆ˜ ๋ณ€์ˆ˜
6+
answer = 0
7+
8+
# ๊ฐ€์žฅ ๋†’์€ ๋ ˆ๋ฒจ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ ์ ์ˆ˜๋ฅผ ์กฐ์ •
9+
for i in range(N - 2, -1, -1): # ๋’ค์—์„œ ๋‘ ๋ฒˆ์งธ ๋ ˆ๋ฒจ๋ถ€ํ„ฐ ์ฒซ ๋ฒˆ์งธ ๋ ˆ๋ฒจ๊นŒ์ง€
10+
if scores[i] >= scores[i + 1]: # ๋‹ค์Œ ๋ ˆ๋ฒจ ์ ์ˆ˜๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๋‹ค๋ฉด
11+
answer += scores[i] - (scores[i + 1] - 1) # ๊ฐ์†Œํ•ด์•ผ ํ•˜๋Š” ํšŸ์ˆ˜ ์ฆ๊ฐ€
12+
scores[i] = scores[i + 1] - 1 # ๋‹ค์Œ ๋ ˆ๋ฒจ๋ณด๋‹ค 1 ์ž‘๊ฒŒ ์„ค์ •
13+
14+
# ๊ฒฐ๊ณผ ์ถœ๋ ฅ
15+
print(answer)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
n = int(input()) # ์„ผ์„œ์˜ ๊ฐœ์ˆ˜
5+
k = int(input()) # ์ง‘์ค‘๊ตญ์˜ ๊ฐœ์ˆ˜
6+
pos = list(map(int, input().split())) # ์„ผ์„œ์˜ ์ขŒํ‘œ
7+
8+
pos = sorted(set(pos)) # ์„ผ์„œ ์œ„์น˜ ์ •๋ ฌ ๋ฐ ์ค‘๋ณต ์ œ๊ฑฐ
9+
distances = [] # ์„ผ์„œ ๊ฐ„ ๊ฑฐ๋ฆฌ ์ฐจ์ด
10+
11+
# ์„ผ์„œ ๊ฐ„ ๊ฑฐ๋ฆฌ ์ฐจ์ด ๊ณ„์‚ฐ
12+
for i in range(1, len(pos)):
13+
distances.append(pos[i] - pos[i-1])
14+
15+
# ๊ฑฐ๋ฆฌ ์ฐจ์ด ํฐ ์ˆœ์„œ๋กœ ์ •๋ ฌ
16+
distances.sort(reverse=True)
17+
18+
# ๊ฐ€์žฅ ํฐ (k-1)๊ฐœ์˜ ๊ฑฐ๋ฆฌ ์ฐจ์ด๋ฅผ ๋นผ๊ณ  ๋‚จ์€ ๊ฑฐ๋ฆฌ๋“ค์˜ ํ•ฉ์ด ์ตœ์†Œ๊ฐ€ ๋˜๋Š” ๊ฑฐ๋ฆฌ ํ•ฉ
19+
min_dist_sum = sum(distances[k-1:])
20+
21+
print(min_dist_sum)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
n = int(input())
5+
6+
# ๊ธฐ๋ณธ ์‹œ๊ฐ„์€ 10์ดˆ
7+
answer = 10
8+
9+
# n์ด 2์˜ ๊ฑฐ๋“ญ์ œ๊ณฑ์ด ๋  ๋•Œ๋งˆ๋‹ค ์‹œ๊ฐ„์„ 1์”ฉ ์ฆ๊ฐ€์‹œํ‚ด
10+
while n > 1:
11+
n //= 2
12+
answer += 1
13+
14+
print(answer)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
import heapq
3+
input = sys.stdin.readline
4+
5+
n = int(input())
6+
rooms = []
7+
8+
# ๊ฐ•์˜ ์ •๋ณด ์ž…๋ ฅ๋ฐ›๊ธฐ
9+
for _ in range(n):
10+
no, start, end = map(int, input().split())
11+
rooms.append((start, end))
12+
13+
# ์‹œ์ž‘ ์‹œ๊ฐ„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ
14+
rooms.sort()
15+
16+
# ์ตœ์†Œ ํž™ ์ดˆ๊ธฐํ™”
17+
min_heap = []
18+
19+
for start, end in rooms:
20+
# ํ˜„์žฌ ๊ฐ•์˜๊ฐ€ ๊ฐ€์žฅ ๋นจ๋ฆฌ ๋๋‚˜๋Š” ๊ฐ•์˜ ์ดํ›„ ์‹œ์ž‘ํ•˜๋ฉด ํ•ด๋‹น ๊ฐ•์˜ ์ข…๋ฃŒ
21+
if min_heap and min_heap[0] <= start:
22+
heapq.heappop(min_heap)
23+
heapq.heappush(min_heap, end)
24+
25+
# ํ•„์š”ํ•œ ์ตœ์†Œ ๊ฐ•์˜์‹ค ๊ฐœ์ˆ˜๋Š” ํž™์˜ ํฌ๊ธฐ
26+
print(len(min_heap))

0 commit comments

Comments
ย (0)