From 96c8700703b6603d2eb963e4d4bfee2778192b79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8E=E1=85=A1=E1=84=8C=E1=85=B5=E1=84=8B=E1=85=AF?= =?UTF-8?q?=E1=86=AB?= Date: Sat, 10 Sep 2022 15:41:37 +0900 Subject: [PATCH] =?UTF-8?q?Solve:=20=EC=B9=B4=EB=93=9C=EA=B2=8C=EC=9E=84?= =?UTF-8?q?=20[#115]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- boj/class5/16566.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 boj/class5/16566.py diff --git a/boj/class5/16566.py b/boj/class5/16566.py new file mode 100644 index 0000000..caa662d --- /dev/null +++ b/boj/class5/16566.py @@ -0,0 +1,35 @@ +# Ex_16566 카드게임 [플5] +# upper bound +def upperBound(target): + s, e = 0, M + + while s < e: + mid = (s + e) // 2 + if cards[mid] <= target: + s = mid + 1 + else: + e = mid + return e + + +def find(x): + if graph[x] != x: + graph[x] = find(graph[x]) + return graph[x] + + +def union(child, parent): + if parent < M: + graph[find(child)] = find(parent) + + +N, M, K = map(int, input().split()) +cards = sorted(map(int, input().split())) +cCards = list(map(int, input().split())) +graph = list(i for i in range(M)) + +for cCard in cCards: + index = find(upperBound(cCard)) + print(cards[index]) + + union(index, index + 1)