본문 바로가기
Problem Solving/SWEA

[SWEA|파이썬] 1208. [S/W 문제해결 기본] 1일차 - Flatten (D3)

by 청량리 물냉면 2023. 5. 7.
반응형
문제

https://tinyurl.com/2h9tsjeu

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

🐍파이썬
T = 10
for test_case in range(1, T + 1):
    dump = int(input())
    height = list(map(int, input().split()))
    for i in range(dump):
    	#min과 max값이 동일하다면 수행종료
        if height[height.index(min(height))] == height[height.index(max(height))]:
            break
        height[height.index(min(height))] += 1	#height의 min값의 인덱스에 해당하는 height원소값에 +1
        height[height.index(max(height))] -= 1	#height의 max값의 인덱스에 해당하는 height원소값에 -1
    print("#{} {}".format(test_case, max(height) - min(height)))

for test_case in range(1, 11):
    dump = int(input())
    boxes = list(map(int, input().split()))
    while dump:	#dump회 반복
        boxes = sorted(boxes)	#매번 오름차순 정렬
        boxes[-1] = boxes[-1] - 1	#최대값에서 -1
        boxes[0] = boxes[0] + 1		#최소값에 +1
        dump -= 1
    print("#{} {}".format(test_case, max(boxes)-min(boxes)))
반응형