- 02 - 09 : First
import sys
sys.stdin = open('input.txt', 'r')
for test_case in range(1, 11):
n = int(input())
arr = list(map(int, input().split()))
num = 0
count = 0
while count < n:
min_box = arr[0]
min_index = 0
max_box = arr[0]
max_index = 0
for i in range(len(arr)):
if arr[i] >= max_box:
max_box = arr[i]
max_index = i
if arr[i] <= min_box:
min_box = arr[i]
min_index = i
min_box += 1
max_box -= 1
count += 1
if min_box == max_box:
num = 0
break
arr[min_index] = min_box
arr[max_index] = max_box
num = max_box - min_box
print('#{} {}'.format(test_case, num))
- 내장함수 사용 X
def Bubble_Sort(arr):
for i in range(len(arr) - 1, 0, -1):
for j in range(i):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return arr
for tc in range(1, 11):
dump = int(input())
box = list(map(int, input().split()))
for i in range(dump):
Bubble_Sort(box)
box[0] += 1
box[len(box) - 1] -= 1
Bubble_Sort(box)
print('#{} {}'.format(tc, box[len(box) - 1] - box[0]))
- 내장함수 사용 O
for tc in range(1, 11):
N = int(input())
box = list(map(int, input().split()))
box.sort()
for i in range(N):
box.sort()
box[0] += 1
box[len(box)-1] -= 1
box.sort()
print('#{} {}'.format(tc, box[len(box)-1]-box[0]))