반응형
문제
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)))
반응형
'Problem Solving > SWEA' 카테고리의 다른 글
[SWEA|파이썬] 1215. [S/W 문제해결 기본] 3일차 - 회문1 (D3) (0) | 2023.05.08 |
---|---|
[SWEA|파이썬] 2805. 농작물 수확하기 (D3) (0) | 2023.05.08 |
[SWEA|파이썬] 2806. N-Queen (D3) (1) | 2023.05.07 |
[SWEA|파이썬] 1244. [S/W 문제해결 응용] 2일차 - 최대 상금 (D3) (0) | 2023.05.07 |
[SWEA|파이썬] 1206. [S/W 문제해결 기본] 1일차 - View (D3) (0) | 2023.05.06 |
[SWEA|파이썬] 5215. 햄버거 다이어트 (D3) (0) | 2023.04.27 |