# 대표값
def run(N, nums):
avg = int(sum(nums) / N + 0.5) # 반올림
min_d, score, idx = 1e9, 0, 0
for i, s in enumerate(nums):
d = abs(s - avg)
if d < min_d: # 최소일때 인덱스와 점수
min_d = d
score = s
idx = i
elif d == min_d and s > score:
score = s
idx = i
return (avg, idx)
N = int(input())
nums = list(map(int, input().split()))
avg, idx = run(N, nums)
print(avg, idx+1)
'파이썬 알고리즘 (인프런) > 코드 구현력 기르기' 카테고리의 다른 글
6. 자릿수의 합 (0) | 2021.01.06 |
---|---|
5. 정다면체 (0) | 2021.01.06 |
3. K번째 큰 수 (0) | 2021.01.06 |
2. K번째 수 (0) | 2021.01.06 |
1. K번째 약수 (0) | 2021.01.06 |