-- 예전 기록/AtCoder

[ AtCoder ] Boot camp for Beginners - ( ABC 156 ) C - Rally

rejo 2024. 1. 29. 11:37

https://atcoder.jp/contests/abc156/tasks/abc156_c

 

C - Rally

AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.

atcoder.jp

 

1부터 100까지 해당 좌표에서 미팅을 열었을 때의 포인트를 전부 계산하여 최소 포인트를 찾는다.

import sys
input = sys.stdin.readline

n = int(input().rstrip())
arr = list(map(int, input().rstrip().split()))
result = -1
for i in range(1, 101):
    now = 0
    for a in arr: now += (i - a)**2
    if result == -1: result = now
    else: result = min(result, now)
print(result)