From 40f5b13695fd040c98abe984e3e7f0f2e48df1dc Mon Sep 17 00:00:00 2001 From: Kimyungi Date: Thu, 3 Nov 2022 16:38:26 +0900 Subject: [PATCH] =?UTF-8?q?[BOJ-2065]=20=EB=82=98=EB=A3=BB=EB=B0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kimyungi --- ...5_\353\202\230\353\243\273\353\260\260.py" | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 "YG/BOJ_2065_\353\202\230\353\243\273\353\260\260.py" diff --git "a/YG/BOJ_2065_\353\202\230\353\243\273\353\260\260.py" "b/YG/BOJ_2065_\353\202\230\353\243\273\353\260\260.py" new file mode 100644 index 0000000..41caeca --- /dev/null +++ "b/YG/BOJ_2065_\353\202\230\353\243\273\353\260\260.py" @@ -0,0 +1,73 @@ +import sys +from queue import deque +input = sys.stdin.readline + +if __name__ == '__main__': + m, t, n = map(int, input().strip().split()) + time = 0 + curr = 'left' + left_q = deque() + right_q = deque() + for i in range(n): + arrive_time, location = input().strip().split() + if location == 'left': + left_q.append((int(arrive_time), i)) + else: + right_q.append((int(arrive_time), i)) + + answer = [0] * (len(left_q) + len(right_q)) + while left_q or right_q: + cnt = 0 + if curr == 'left': + if left_q: + left = left_q[0][0] + else: + left = 100001 + if right_q: + right = right_q[0][0] + else: + right = 100001 + + if left <= time or left <= right: # left start + time = max(time, left) + while left_q and left_q[0][0] <= time and cnt < m: + _, idx = left_q.popleft() + cnt += 1 + answer[idx] = time + t + time += t + curr = 'right' + else: # right start + time = max(time, right) + t + while right_q and right_q[0][0] <= time and cnt < m: + _, idx = right_q.popleft() + cnt += 1 + answer[idx] = time + t + time += t + else: + if left_q: + left = left_q[0][0] + else: + left = 100001 + if right_q: + right = right_q[0][0] + else: + right = 100001 + + if right <= time or right <= left: # right start + time = max(time, right) + while right_q and right_q[0][0] <= time and cnt < m: + _, idx = right_q.popleft() + cnt += 1 + answer[idx] = time + t + time += t + curr = 'left' + else: # left start + time = max(time, left) + t + while left_q and left_q[0][0] <= time and cnt < m: + _, idx = left_q.popleft() + cnt += 1 + answer[idx] = time + t + time += t + + for i in answer: + print(i) \ No newline at end of file