結果

問題 No.837 Noelちゃんと星々2
ユーザー maspy
提出日時 2020-02-02 13:22:06
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 31,940 KB
最終ジャッジ日時 2024-06-11 14:27:51
合計ジャッジ時間 3,878 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

N,*Y = map(int,read().split())

Y.sort()

if Y[0] == Y[-1]:
    print(1)
    exit()

def calc_left_sum(Y):
    n_left = 0
    right = deque()
    s_l = 0
    s_r = 0
    ret = [10 ** 18]
    for y in Y:
        right.append(y)
        s_r += y
        if n_left + 1 < len(right):
            n_left += 1
            x = right.popleft()
            s_l += x
            s_r -= x
        mid = right[0]
        D = (mid * n_left - s_l)
        D += (s_r - mid * len(right))
        ret.append(D)
    return ret

L = calc_left_sum(Y)
R = calc_left_sum([-y for y in Y[::-1]])

answer = min(x+y for x,y in zip(L[1:N], R[1:N][::-1]))
print(answer)
0