結果

問題 No.972 選び方のスコア
ユーザー maspymaspy
提出日時 2020-03-18 13:21:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,447 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 32,108 KB
最終ジャッジ日時 2024-05-08 02:15:34
合計ジャッジ時間 35,146 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,407 ms
31,384 KB
testcase_01 AC 1,447 ms
31,200 KB
testcase_02 AC 1,330 ms
30,272 KB
testcase_03 AC 657 ms
21,160 KB
testcase_04 AC 1,370 ms
31,852 KB
testcase_05 AC 1,319 ms
31,792 KB
testcase_06 AC 1,353 ms
31,792 KB
testcase_07 AC 1,024 ms
26,136 KB
testcase_08 AC 1,173 ms
31,376 KB
testcase_09 AC 1,147 ms
30,624 KB
testcase_10 AC 1,282 ms
31,092 KB
testcase_11 AC 1,240 ms
31,208 KB
testcase_12 AC 1,326 ms
31,344 KB
testcase_13 AC 1,376 ms
31,344 KB
testcase_14 AC 1,317 ms
31,284 KB
testcase_15 AC 1,447 ms
30,956 KB
testcase_16 AC 1,321 ms
31,340 KB
testcase_17 AC 1,302 ms
31,244 KB
testcase_18 AC 28 ms
10,752 KB
testcase_19 AC 1,350 ms
32,108 KB
testcase_20 AC 1,387 ms
31,916 KB
testcase_21 AC 1,428 ms
32,104 KB
testcase_22 AC 1,333 ms
30,700 KB
testcase_23 AC 1,367 ms
32,076 KB
testcase_24 AC 1,324 ms
31,940 KB
testcase_25 AC 28 ms
10,752 KB
testcase_26 AC 26 ms
10,624 KB
testcase_27 AC 26 ms
10,624 KB
testcase_28 AC 26 ms
10,624 KB
testcase_29 AC 26 ms
10,624 KB
testcase_30 AC 27 ms
10,624 KB
testcase_31 AC 26 ms
10,752 KB
testcase_32 AC 27 ms
10,880 KB
testcase_33 AC 26 ms
10,752 KB
testcase_34 AC 26 ms
10,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
N, *A = map(int, read().split())
A = sorted(A)
Acum = tuple(itertools.accumulate(A))


def solve(mid):
    left = mid
    right = N - 1 - mid
    n = min(left, right)
    if n == 0:
        return 0
    LR = mid - 1
    LL = LR - n + 1
    RR = N - 1
    RL = RR - n + 1
    left = -1  # とらない
    right = n  # とる
    while left + 1 < right:
        x = (left + right) // 2
        if A[LL + x] + A[RL + x] <= 2 * A[mid]:
            left = x
        else:
            right = x
    if right == n + 1:
        return 0
    i = left
    SL = Acum[LR]
    if LL + i >= 0:
        SL -= Acum[LL + i]
    SR = Acum[RR] - Acum[RL + i]
    S = SL + SR + A[mid]
    n_elem = (LR - LL - left) * 2 + 1
    return S - A[mid] * n_elem


answer = max(solve(i) for i in range(N))
print(answer)
0