7795 먹을 것인가 먹힐 것인가

장종민·2023년 8월 17일

boj

목록 보기
15/22

def binary_search(fish_list, eat_fish):
    
    s = 0
    e = len(fish_list) - 1
    result = -1
    while s <= e:

        m = (s + e)//2
        
        if fish_list[m] < eat_fish:
            result = m
            s = m + 1
        else:
            e = m - 1

    return result



T = int(input())
for i in range(T):
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    B = sorted(list(map(int, input().split())))
    cnt = 0
    for j in A:
        cnt += (binary_search(B, j) + 1) # j 물고기가 먹을 수 있는 총 물고기 개수
    print(cnt)
    
profile
비전공 오르미부트캠프 2기

0개의 댓글