forked from 16-SulGore/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |