結果

問題 No.837 Noelちゃんと星々2
ユーザー lloyz
提出日時 2022-07-12 23:42:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 623 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,520 KB
実行使用メモリ 128,508 KB
最終ジャッジ日時 2024-06-23 21:52:25
合計ジャッジ時間 4,126 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

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

if len(set(Y)) == 1:
    print(1)
    exit()
elif len(set(Y)) == 2:
    print(0)
    exit()

Y.sort()
accumY = [0]
for i in range(n):
    accumY.append(accumY[-1] + Y[i])
ans = 10**18
for i in range(1, n):
    res = 0
    if i % 2 == 1:
        res += accumY[i] - 2 * accumY[i // 2] - Y[i // 2]
    else:
        res += accumY[i] - 2 * accumY[i // 2]
    j = n - i
    if j % 2 == 1:
        res += accumY[n] - 2 * accumY[i + j // 2] - Y[i + j // 2] + accumY[i]
    else:
        res += accumY[n] - 2 * accumY[i + j // 2] + accumY[i]
    ans = min(ans, res)
print(ans)
0