結果

問題 No.837 Noelちゃんと星々2
ユーザー titia
提出日時 2022-04-12 04:09:14
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 410 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 21,668 KB
最終ジャッジ日時 2024-12-16 05:29:18
合計ジャッジ時間 7,039 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

# こういう問題は中央値を考える

import sys
input = sys.stdin.readline
from itertools import accumulate

N=int(input())
Y=sorted(map(int,input().split()))

if max(Y)==min(Y):
    print(1)
    exit()

ANS=1<<100

S=list(accumulate(Y))
S.append(0)

for i in range(N-1):
    score=0

    x=i//2
    score+=Y[x]*(x+1)-S[x]
    score+=S[i]-S[x]-Y[x]*(i-x)

    x=(i+1+N-1)//2
    score+=Y[x]*(x-i)-S[x]+S[i]
    score+=S[N-1]-S[x]-Y[x]*(N-1-x)

    ANS=min(ANS,score)

print(ANS)
0