結果

問題 No.972 選び方のスコア
ユーザー NoneNone
提出日時 2021-03-25 22:08:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 893 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 116,132 KB
最終ジャッジ日時 2023-08-18 04:47:02
合計ジャッジ時間 8,600 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 226 ms
116,132 KB
testcase_01 AC 220 ms
115,988 KB
testcase_02 AC 215 ms
115,424 KB
testcase_03 AC 155 ms
99,984 KB
testcase_04 AC 219 ms
114,516 KB
testcase_05 AC 217 ms
114,208 KB
testcase_06 AC 217 ms
114,340 KB
testcase_07 AC 188 ms
101,392 KB
testcase_08 AC 185 ms
114,376 KB
testcase_09 AC 182 ms
113,724 KB
testcase_10 AC 183 ms
114,256 KB
testcase_11 AC 181 ms
114,200 KB
testcase_12 AC 195 ms
114,672 KB
testcase_13 AC 202 ms
114,476 KB
testcase_14 AC 196 ms
114,676 KB
testcase_15 AC 205 ms
115,784 KB
testcase_16 AC 198 ms
116,112 KB
testcase_17 AC 197 ms
115,800 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 74 ms
71,412 KB
testcase_26 AC 74 ms
71,284 KB
testcase_27 AC 73 ms
71,412 KB
testcase_28 AC 73 ms
71,436 KB
testcase_29 AC 72 ms
71,444 KB
testcase_30 AC 74 ms
71,048 KB
testcase_31 AC 74 ms
71,348 KB
testcase_32 AC 74 ms
71,148 KB
testcase_33 AC 78 ms
75,652 KB
testcase_34 AC 74 ms
71,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def binary_search_int(ok, ng, test):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if test(mid):
            ok = mid
        else:
            ng = mid
    return ok

def example():
    global input
    example = iter(
        """
3
1 2 10
        """
            .strip().split("\n"))
    input = lambda: next(example)



##############################################################
import sys
input = sys.stdin.readline

# example()

def test(x):
    return A[i-x]+A[-1-x]-m>=0

N=int(input())
A=list(map(int, input().split()))
A.sort()
acc=[0]
for a in A:
    acc.append(acc[-1]+a)

res=0
for i in range(N):
    m=A[i]
    k=binary_search_int(0,min(i+1,N-i),test)
    S=acc[i+1]-acc[i-k] +acc[N]-acc[N-k] -m*(2*k+1)
    res=max(res,S)
print(res)
0