結果

問題 No.609 Noelちゃんと星々
ユーザー kichirb3
提出日時 2018-03-24 00:14:21
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 884 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 21,924 KB
最終ジャッジ日時 2024-06-25 00:34:55
合計ジャッジ時間 8,221 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.609 Noelちゃんと星々
https://yukicoder.me/problems/no/609

"""
import sys
from sys import stdin
input = stdin.readline


def calc_score(n, stars):
    res = [abs(x - n) for x in stars]
    return sum(res)


def solve(stars):
    ans = float('inf')
    ub = max(stars)
    lb = min(stars)

    ub_score = calc_score(ub, stars)
    lb_score = calc_score(lb, stars)
    while ub > lb + 1:
        mid = (ub + lb) // 2
        mid_score = calc_score(mid, stars)

        if ub_score >= mid_score:
            ub = mid
            ub_score = mid_score
        elif lb_score >= mid_score:
            lb = mid
            lb_score = mid_score
    return min(ub_score, lb_score)


def main(args):
    N = int(input())
    stars = [int(x) for x in input().split()]
    ans = solve(stars)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
0