input
A,B
A,B.len ≤ 1,000,000,000output
res + 1 해주고 B에서 해당 요소 popO(n^2)O(n) 타임이 소요되어서 어차피 못씀..O(nlogn)A,B 모두 정렬하고, A를 순회하면서 B가 이길 수 있는 모든 경우의 수만 체크이진 탐색
def solution(A, B):
B.sort()
res = 0
for a_num in A:
s = 0
e = len(B)-1
index = 0
while s < e:
mid = (s+e) // 2
index = mid
if B[mid] > a_num:
e -= 1
else:
s += 1
if B[index] > a_num:
res += 1
B.pop(index)
return res
그리디
def solution(A, B):
A.sort(reverse=True)
B.sort(reverse=True)
res = 0
b_index = 0
# B에서 A를 이길 수 있는 경우가 몇개인지만 찾으면 됨
# 이길 수 있으면 다음으로 작은 B의 요소가 이길 수 있는 지 체크
for a_num in A:
if B[b_index] > a_num:
res += 1
b_index += 1
return res