๐ฃ ์๋ด์ ์ธ์
1. ๋ฌธ์ ๋งํฌ
2. ์ฝ๋
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
# FIFO
# ๊ฐ ๋ฉํ ๋น ๋๋๋ ์๊ฐ ๊ธฐ๋ก
# ๋๋๋ ์๊ฐ์ด ๋ ๋น ๋ฅธ ๋ฉํ ์๊ฒ ์๋ด ์งํ
# ์ฐ์ ๋ฉํ ํ๋ช
์ฉ ๋ฐฐ์ ํ๊ณ ์ดํ, ๊ธฐ๋ค๋ฆฌ๋ ์๊ฐ์ด ๊ฐ์ฅ ๊ธด ํ์๊ฒ ๋ฉํ ์ถ๊ฐ ๋ฐฐ์
def min_time(start_time, end_time, group_queue):
wait_time = 0
min_v = int(1e9)
target_idx = 0
for i in range(len(group_queue)):
if group_queue[i] <= start_time:
target_idx = i
min_v = 0
break
# ์๊ฐ์ฐจ๊ฐ ์ต์๊ฐ ๋๋ ๊ฐ ์ฐพ๊ธฐ
if min_v > group_queue[i] - start_time:
target_idx = i
min_v = group_queue[i] - start_time
group_queue[target_idx] = max(start_time, group_queue[target_idx]) + end_time # ๋๋๋ ์๊ฐ์ผ๋ก ๋ฐ๊ฟ์ค
wait_time = min_v
return wait_time, group_queue
def solution(k, n, reqs):
answer = 0
wait_queue = [[0] for _ in range(k + 1)]
n = n - k
while n >= 0:
wait_time = [0] * (k + 1) # ๊ฐ ๊ทธ๋ฃน๋ณ๋ก ๊ธฐ๋ค๋ ค์ผ ํ๋ ์๊ฐ ์ดํฉ
for start, end, g in reqs:
t, q = min_time(start, end, wait_queue[g])
wait_time[g] += t
wait_queue[g] = q
max_time = max(wait_time) # ๊ฐ ๊ทธ๋ฃน ์ค ์ต๋๋ก ๊ธฐ๋ค๋ ค์ผํ๋ ๊ทธ๋ฃน์ ์๊ฐ
wait_queue[wait_time.index(max_time)].append(0)
n -= 1
for i in range(k + 1):
wait_queue[i] = len(wait_queue[i]) * [0]
answer = sum(wait_time)
return answer
This post is licensed under CC BY 4.0 by the author.