結果

問題 No.972 選び方のスコア
ユーザー maspymaspy
提出日時 2020-03-18 13:21:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,183 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 10,996 KB
実行使用メモリ 29,504 KB
最終ジャッジ日時 2023-08-20 19:51:56
合計ジャッジ時間 28,691 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,156 ms
28,752 KB
testcase_01 AC 1,170 ms
28,564 KB
testcase_02 AC 1,108 ms
27,716 KB
testcase_03 AC 532 ms
18,620 KB
testcase_04 AC 1,162 ms
29,232 KB
testcase_05 AC 1,150 ms
29,104 KB
testcase_06 AC 1,150 ms
29,184 KB
testcase_07 AC 859 ms
23,528 KB
testcase_08 AC 920 ms
28,692 KB
testcase_09 AC 892 ms
28,040 KB
testcase_10 AC 946 ms
28,584 KB
testcase_11 AC 936 ms
28,616 KB
testcase_12 AC 1,007 ms
28,632 KB
testcase_13 AC 1,041 ms
28,644 KB
testcase_14 AC 1,007 ms
28,596 KB
testcase_15 AC 1,086 ms
28,456 KB
testcase_16 AC 1,033 ms
28,580 KB
testcase_17 AC 1,033 ms
28,660 KB
testcase_18 AC 16 ms
8,276 KB
testcase_19 AC 1,146 ms
29,504 KB
testcase_20 AC 1,168 ms
29,468 KB
testcase_21 AC 1,151 ms
29,332 KB
testcase_22 AC 1,105 ms
28,440 KB
testcase_23 AC 1,183 ms
29,336 KB
testcase_24 AC 1,144 ms
29,404 KB
testcase_25 AC 16 ms
8,192 KB
testcase_26 AC 16 ms
8,212 KB
testcase_27 AC 16 ms
8,184 KB
testcase_28 AC 16 ms
8,160 KB
testcase_29 AC 16 ms
8,124 KB
testcase_30 AC 16 ms
8,160 KB
testcase_31 AC 16 ms
8,184 KB
testcase_32 AC 16 ms
8,304 KB
testcase_33 AC 16 ms
8,268 KB
testcase_34 AC 17 ms
8,168 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