tc = int(input()) for idx in range(1, tc+1): n, m = map(int, input().split()) # 컨테이너 수 n, 트럭 수 m weight = sorted(list(map(int, input().split())), reverse=True) # 화물의 무게 trucks = sorted(list(map(int, input().split()))) # 트럭의 적재 용량(pop쓸거라서 reverse 안씀) total_w = 0 t = trucks.pop() # 큰 트럭 가져와 for w in weight: # 화물 무거운 것부터 탐색 if w <= t: # 화물 트럭에 실을 수 있다면 total_w += w # 화물 전체 무게에 더해주기 if trucks: t = trucks.pop() # 다음 트럭 오세요 else: break # 트럭 없다면 중단 print('#{} {}'.format(idx, total_w))
포인트 : 트럭당 한 개의 컨테이너를 운반할 수 있으니 각 트럭에 최대한 무거운 화물을 싣도록 한다.
'Algorithm > SW Expert Academy' 카테고리의 다른 글
[Python] 5203. 베이비진 게임 (0) | 2021.10.05 |
---|---|
[Python] 5202. 화물도크 (0) | 2021.10.05 |
[Python] 5189. 전자카트 (0) | 2021.10.03 |
[Python] 1244. 최대 상금 (1) | 2021.10.01 |
[Python] 5188. 최소합 (0) | 2021.10.01 |