Problem :

https://www.hackerrank.com/challenges/equal-stacks/problem


My Solution :

#!/usr/bin/env python3


def equal_stacks(h1, h2, h3):
    sum_h1 = sum(h1)
    sum_h2 = sum(h2)
    sum_h3 = sum(h3)
    while not (sum_h1 == sum_h2 == sum_h3):
        max_h = max(sum_h1, sum_h2, sum_h3)
        if sum_h1 == max_h:
            sum_h1 -= h1.pop()
        if sum_h2 == max_h:
            sum_h2 -= h2.pop()
        if sum_h3 == max_h:
            sum_h3 -= h3.pop()
    return sum_h1


_ = input()
h1 = list(map(int, input().rstrip().split()[::-1]))
h2 = list(map(int, input().rstrip().split()[::-1]))
h3 = list(map(int, input().rstrip().split()[::-1]))
result = equal_stacks(h1, h2, h3)
print(result)


Comment :

모난 돌이 정 맞는다. 모든 실린더의 키가 같아질 때까지 매회 키 큰 실린더를 깎아내린다.