Skip to content

Commit 1ed49b0

Browse files
authored
Merge pull request #114 from AlgorithmStudy-Allumbus/minjeong
Minjeong / 12μ›” 4μ£Όμ°¨ / 3문제
2 parents 21f655a + 64f814f commit 1ed49b0

3 files changed

+74
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import sys
2+
3+
input = sys.stdin.readline
4+
5+
N, K = map(int, input().split()) # N: λ©€ν‹°νƒ­ ꡬ멍 개수, K: μ „κΈ°μš©ν’ˆ 총 μ‚¬μš©νšŸμˆ˜
6+
items = list(map(int, input().split())) # μ „κΈ°μš©ν’ˆ μ‚¬μš© μˆœμ„œ
7+
multitap = [] # ν˜„μž¬ λ©€ν‹°νƒ­
8+
cnt = 0 # ν”ŒλŸ¬κ·Έλ₯Ό λ½‘λŠ” 횟수
9+
10+
for i in range(K):
11+
# 이미 κ½‚ν˜€μžˆλŠ” 경우
12+
if items[i] in multitap:
13+
continue
14+
15+
# 멀티탭에 μžλ¦¬κ°€ μžˆλŠ” 경우
16+
if len(multitap) < N:
17+
multitap.append(items[i])
18+
else:
19+
# ꡐ체할 μ „κΈ°μš©ν’ˆ μ°ΎκΈ°
20+
remove_device = 0
21+
most_late_device = 0
22+
for d in multitap:
23+
if d not in items[i:]: # μ•žμœΌλ‘œ μ‚¬μš©λ˜μ§€ μ•ŠλŠ”λ‹€λ©΄ λ°”λ‘œ 제거
24+
remove_device = d
25+
break
26+
27+
else: # λͺ¨λ“  κΈ°κΈ°κ°€ λ‹€ μ‚¬μš©λ˜μ–΄μ•Ό ν•œλ‹€λ©΄, κ°€μž₯ λ‚˜μ€‘μ— μ‚¬μš©λ˜λŠ” κΈ°κΈ°λ₯Ό 제거
28+
later_device = items[i:].index(d)
29+
if later_device > most_late_device:
30+
most_late_device = later_device
31+
remove_device = d
32+
33+
# ν”ŒλŸ¬κ·Έ ꡐ체
34+
multitap.remove(remove_device)
35+
multitap.append(items[i])
36+
cnt += 1
37+
38+
# κ²°κ³Ό 좜λ ₯
39+
print(cnt)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
# μž…λ ₯
5+
N = int(input())
6+
meetings = [[0, 0] for _ in range(N)]
7+
8+
for i in range(N):
9+
start, end = map(int, input().split())
10+
meetings[i][0] = start
11+
meetings[i][1] = end
12+
13+
# λλ‚˜λŠ” μ‹œκ°„μ„ κΈ°μ€€μœΌλ‘œ μ •λ ¬, λλ‚˜λŠ” μ‹œκ°„μ΄ κ°™μœΌλ©΄ μ‹œμž‘ μ‹œκ°„μ„ κΈ°μ€€μœΌλ‘œ μ •λ ¬
14+
meetings.sort(key=lambda x: (x[1], x[0]))
15+
16+
cnt = 0 # 회의 개수
17+
last_end_time = 0 # λ§ˆμ§€λ§‰μœΌλ‘œ λ°°μ •λœ 회의의 μ’…λ£Œ μ‹œκ°„
18+
19+
for start, end in meetings:
20+
if start >= last_end_time: # ν˜„μž¬ 회의 μ‹œμž‘ μ‹œκ°„μ΄ λ§ˆμ§€λ§‰ 회의 μ’…λ£Œ μ‹œκ°„ 이후라면
21+
cnt += 1 # 회의 λ°°μ •
22+
last_end_time = end # 회의 μ’…λ£Œ μ‹œκ°„ μ—…λ°μ΄νŠΈ
23+
24+
print(cnt)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
S = int(input())
2+
n = 0 # μžμ—°μˆ˜ 개수
3+
total = 0 # λˆ„μ  ν•©
4+
5+
# 1λΆ€ν„° μ°¨λ‘€λŒ€λ‘œ λ”ν•˜κΈ°
6+
while total <= S:
7+
n += 1
8+
total += n
9+
10+
# λ§ˆμ§€λ§‰μœΌλ‘œ λ”ν•œ 값이 Sλ₯Ό μ΄ˆκ³Όν–ˆμœΌλ―€λ‘œ n-1이 μ •λ‹΅
11+
print(n - 1)

0 commit comments

Comments
Β (0)