結果

問題 No.609 Noelちゃんと星々
ユーザー brthyyjpbrthyyjp
提出日時 2020-06-27 06:49:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 392 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 93,100 KB
最終ジャッジ日時 2023-09-18 18:59:56
合計ジャッジ時間 4,383 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
88,944 KB
testcase_01 AC 98 ms
80,836 KB
testcase_02 AC 90 ms
78,644 KB
testcase_03 AC 93 ms
80,372 KB
testcase_04 AC 85 ms
76,980 KB
testcase_05 AC 116 ms
91,692 KB
testcase_06 AC 110 ms
88,452 KB
testcase_07 AC 96 ms
83,160 KB
testcase_08 AC 81 ms
76,156 KB
testcase_09 AC 89 ms
78,936 KB
testcase_10 AC 100 ms
84,780 KB
testcase_11 AC 98 ms
83,912 KB
testcase_12 AC 107 ms
87,508 KB
testcase_13 AC 81 ms
76,160 KB
testcase_14 AC 79 ms
76,220 KB
testcase_15 AC 111 ms
89,616 KB
testcase_16 AC 118 ms
93,100 KB
testcase_17 AC 108 ms
89,108 KB
testcase_18 AC 86 ms
78,372 KB
testcase_19 AC 110 ms
88,300 KB
testcase_20 AC 119 ms
91,960 KB
testcase_21 AC 116 ms
91,820 KB
testcase_22 AC 117 ms
91,768 KB
testcase_23 AC 117 ms
91,968 KB
testcase_24 AC 117 ms
91,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
Y = list(map(int, input().split()))
Y.sort()

import math

if n%2 == 1:
    ans = 0
    for i in range(n):
        ans += abs(Y[i]-Y[n//2])
else:
    y1 = math.floor((Y[n//2-1]+Y[n//2])/2)
    y2 = math.ceil((Y[n//2-1]+Y[n//2])/2)
    ans1 = 0
    ans2 = 0
    for i in range(n):
        ans1 += abs(Y[i]-y1)
        ans2 += abs(Y[i]-y2)
    ans = min(ans1, ans2)
print(ans)
0