fork download
  1. import bisect
  2.  
  3. # 테스트 케이스 개수 입력
  4. T = int(input())
  5.  
  6. for _ in range(T):
  7. # N, M 입력
  8. N, M = map(int, input().split())
  9.  
  10. # A와 B 크기 리스트 입력
  11. A = list(map(int, input().split()))
  12. B = list(map(int, input().split()))
  13.  
  14. # A 리스트를 오름차순 정렬
  15. A.sort()
  16.  
  17. # A가 B보다 큰 쌍의 개수
  18. count = 0
  19.  
  20. # 각 B의 크기에 대해 A에서 큰 값을 찾는 방법
  21. for b in B:
  22. # bisect_right는 b보다 큰 값이 시작되는 인덱스를 찾음
  23. idx = bisect.bisect_right(A, b)
  24. count += len(A) - idx
  25.  
  26. # 결과 출력
  27. print(count)
Success #stdin #stdout 0.09s 14148KB
stdin
2
5 3
8 1 7 3 1
3 6 1
3 4
2 13 7
103 11 290 215
stdout
7
1