FeelingXD

[๋ฐฑ์ค€-7795] ๋จน์„๊ฒƒ์ธ๊ฐ€ ๋จนํž๊ฒƒ์ธ๊ฐ€ ๋ณธ๋ฌธ

์นดํ…Œ๊ณ ๋ฆฌ ์—†์Œ

[๋ฐฑ์ค€-7795] ๋จน์„๊ฒƒ์ธ๊ฐ€ ๋จนํž๊ฒƒ์ธ๊ฐ€

FeelingXD 2024. 1. 5. 07:05

โ“ Problem

๐Ÿค” How

  • A ๋ฆฌ์ŠคํŠธ์˜ ์›์†Œ๋งˆ๋‹ค ์ด์ง„ํƒ์ƒ‰์„ ์ง„ํ–‰ํ•ด์„œ ํ”ผํฌ์ธ๋ฑ์Šค๋ฅผ ์ฐพ์•„ B์˜ ๊ธธ์ด-ํ”ผํฌ์ธ๋ฑ์Šค(A๋ฆฌ์ŠคํŠธ ์›์†Œ ๋ณด๋‹ค์ž‘์€ ์ตœ๋Œ€ ์ธ๋ฑ์Šค) ๋ฅผ ๊ฐ’์— ํ•ฉ์‚ฐํ•ด์ฃผ๋Š” ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผํ•˜์˜€๋‹ค.

โ— Solve

# ๋จน์„ ๊ฒƒ์ธ๊ฐ€ ๋จนํž ๊ฒƒ์ธ๊ฐ€
import sys
input =sys.stdin.readline
def action():
    len_A,len_B=map(int,input().split())

    list_A=list(map(int,input().split())) # A ๋ฆฌ์ŠคํŠธ
    list_B=sorted(list(map(int,input().split()))) # B ๋ฆฌ์ŠคํŠธ
    ans=0

    for v in list_A:
        l=0
        r=len_B-1
        m_i=-1 # ๊ธฐ๋ณธ๊ฐ’ ์ดˆ๊ธฐํ™”
        while l<=r and v>list_B[0]: # 2์ง„ ํƒ์ƒ‰
            mid=(l+r)//2
            if v>list_B[mid]:
                m_i=mid
                l=mid+1
            else:
                r=mid-1
        ans+= m_i+1
    print(ans) 




    pass
def solution():
    for _ in range(int(input())):
        action()
    pass
if __name__=="__main__": # ์‹คํ–‰๋˜๋Š” ๋ถ€๋ถ„
    solution()
    pass