카테고리 없음

[백준/python] 7795번: 먹을 것인가 먹힐 것인가

Jinn_12609 2024. 11. 2. 15:54

문제

 

https://www.acmicpc.net/problem/7795


Algorithm

sort()함수를 통해 정렬한 후 각 경우마다 A가 B보다 더 클 때 j에 저장한 후 count에 더한다.

 


 

 

Code

T = int(input())

for _ in range(T):
    N, M = map(int, input().split())
    sizes_A = list(map(int, input().split()))
    sizes_B = list(map(int, input().split()))
    
    sizes_A.sort()  
    sizes_B.sort() 
    
    count = 0  
    j = 0

    for i in range(N):
        while j < M and sizes_B[j] < sizes_A[i]:
            j += 1
        count += j

    print(count)