結果

問題 No.837 Noelちゃんと星々2
ユーザー tails1434
提出日時 2020-01-06 22:03:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 705 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 81,980 KB
実行使用メモリ 140,636 KB
最終ジャッジ日時 2024-11-23 00:08:11
合計ジャッジ時間 8,584 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 6 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import statistics
from itertools import accumulate

def main():
    N = int(input())
    Y = list(map(int, input().split()))
    sort_Y = sorted(Y)
    if len(set(Y)) == 1:
        print(1)
        exit()
    elif len(set(Y)) == 2:
        print(0)
        exit()

    A = list(accumulate(sort_Y))
    m = Y[N // 2]
    ans = float('inf')
    first_half = 0
    second_half = 0
    for y in sort_Y:
        second_half += abs(m - y)
    for i in range(N-1):
        m1 = sort_Y[i // 2]
        m2 = sort_Y[(i + N) // 2]

        first_half += sort_Y[i] - m1
        second_half -= m2 - sort_Y[i]

        ans = min(ans, first_half + second_half)

    print(ans)
    

if __name__ == "__main__":
    main()
0