문제 조건


input

output

문제 해석


코드


  1. 이진 탐색

    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 
    
  2. 그리디

    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