結果

問題 No.609 Noelちゃんと星々
ユーザー kichirb3kichirb3
提出日時 2018-03-24 00:14:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 884 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 19,380 KB
最終ジャッジ日時 2023-09-07 06:10:12
合計ジャッジ時間 7,784 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

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