Skip to content

Commit

Permalink
Solve: 카드게임 [16-SulGore#115]
Browse files Browse the repository at this point in the history
  • Loading branch information
Cha-Ji committed Sep 10, 2022
1 parent 1a6d9c2 commit 96c8700
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions boj/class5/16566.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 96c8700

Please sign in to comment.