結果

問題 No.609 Noelちゃんと星々
ユーザー GrayCoderGrayCoder
提出日時 2017-12-09 20:52:56
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 421 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 27,864 KB
最終ジャッジ日時 2024-11-30 05:29:42
合計ジャッジ時間 3,882 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from bisect import bisect

def main():
    N = int(input())
    Y = tuple(map(int, input().split()))

    if N == 1:
        print(0)
        return

    c = Counter(Y).most_common()
    y = sorted(Y)
    idx = N // 2
    dist = float('inf')
    for i in (c[0][0], y[idx]):
        n = 0
        for j in y:
            n += abs(i - j)
        dist = min(dist, n)

    print(dist)

main()
0