코딩테스트/프로그래머스

[프로그래머스][완전탐색] 16498. 작은 벌점

박소민 2024. 11. 21. 10:47
16498. 작은 벌점

 

 

  • 내 풀이
    • 리스트에 빼고 넣고 할 필요 없이 매번 새로 넣어주는 것이 좋음
    • 방법
      • 가장 작은 값 3개를 빼서 비교했을때 
      • 가장 큰 값을 늘려봤자 차이는 커지기만 함
        • => 가장 작은 값을 키워야함
      • min값의 idx값을 높여가면서 확인
    • min값의 인덱스값을 높였는데 범위를 넘어가면 다른 것을 더 볼 필요없다는 점
      • min값이 동일하게 2개가 있더라도 더 볼 필요없음
from collections import defaultdict

a, b, c = map(int, input().split())
alst = sorted(map(int, input().split()))
blst = sorted(map(int, input().split()))
clst = sorted(map(int, input().split()))

idx_dict = defaultdict(int)
answer = float('inf')

while idx_dict[0] < a and idx_dict[1] < b and idx_dict[2] < c:
    tmp = [alst[idx_dict[0]], blst[idx_dict[1]], clst[idx_dict[2]]]
    minV = min(tmp)
    maxV = max(tmp)
    min_idx = tmp.index(minV)

    answer = min(answer, maxV - minV)

    idx_dict[min_idx] += 1

print(answer)