practivceAlgorithm/swexpertacademy

[SWEA][Python] 5201 컨테이너 운반

findTheValue 2021. 9. 28. 03:25

요새 비슷한 문제 너무 많이 풀었다. 매칭문제. 투포인터로 매칭

 

for test in range(1, int(input()) + 1):
    N, M = map(int, input().split())
    w = list(map(int, input().split()))
    t = list(map(int, input().split()))
    t.sort(reverse=True)
    w.sort(reverse=True)
    answer = 0
    left = 0
    for truck in t:
        while left < N and truck < w[left]:
            left += 1
        if left == N: break
        answer += w[left]
        left += 1
        
    print(f'#{test} {answer}')