꾸준히 합시다
백준 파이썬 7795번: 먹을 것인가 먹힐 것인가 본문
https://www.acmicpc.net/problem/7795
7795번: 먹을 것인가 먹힐 것인가
심해에는 두 종류의 생명체 A와 B가 존재한다. A는 B를 먹는다. A는 자기보다 크기가 작은 먹이만 먹을 수 있다. 예를 들어, A의 크기가 {8, 1, 7, 3, 1}이고, B의 크기가 {3, 6, 1}인 경우에 A가 B를 먹을
www.acmicpc.net
문제 유형: 정렬, 이분 탐색, 두 포인터
# Solution 1 - 시간 초과
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
for i in range(n):
for j in range(m):
if a[i] > b[j]:
count+= 1
print(count)
# Solution 2
import sys, bisect
input = sys.stdin.readline
for _ in range(int(input())):
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
count = 0
for el in a:
count += (bisect.bisect(b, el - 1))
print(count)
'코딩 테스트 문제 풀이' 카테고리의 다른 글
백준 파이썬 7567번: 그릇 (0) | 2021.07.24 |
---|---|
백준 파이썬 2476번: 주사위 게임 (0) | 2021.07.23 |
백준 파이썬 5355번: 화성 수학 (0) | 2021.07.20 |
백준 파이썬 2720번: 세탁소 사장 동혁 (0) | 2021.07.19 |
백준 파이썬 2902번: KMP는 왜 KMP일까? (0) | 2021.07.18 |
Comments