結果

問題 No.972 選び方のスコア
ユーザー NoneNone
提出日時 2021-03-25 22:39:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 915 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 87,056 KB
実行使用メモリ 116,144 KB
最終ジャッジ日時 2023-08-18 05:15:07
合計ジャッジ時間 8,460 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 245 ms
115,848 KB
testcase_01 AC 243 ms
116,000 KB
testcase_02 AC 241 ms
115,524 KB
testcase_03 AC 172 ms
99,212 KB
testcase_04 AC 240 ms
114,276 KB
testcase_05 WA -
testcase_06 AC 234 ms
114,172 KB
testcase_07 AC 211 ms
101,068 KB
testcase_08 AC 207 ms
114,336 KB
testcase_09 AC 205 ms
114,016 KB
testcase_10 AC 177 ms
114,220 KB
testcase_11 AC 181 ms
114,268 KB
testcase_12 AC 213 ms
114,908 KB
testcase_13 AC 201 ms
114,304 KB
testcase_14 AC 214 ms
114,936 KB
testcase_15 AC 236 ms
115,732 KB
testcase_16 AC 246 ms
116,144 KB
testcase_17 AC 246 ms
115,908 KB
testcase_18 AC 76 ms
71,280 KB
testcase_19 AC 243 ms
106,496 KB
testcase_20 AC 237 ms
106,360 KB
testcase_21 AC 238 ms
106,248 KB
testcase_22 WA -
testcase_23 AC 239 ms
106,576 KB
testcase_24 AC 242 ms
106,716 KB
testcase_25 AC 74 ms
71,224 KB
testcase_26 AC 73 ms
71,284 KB
testcase_27 AC 74 ms
71,212 KB
testcase_28 AC 73 ms
71,200 KB
testcase_29 AC 72 ms
71,212 KB
testcase_30 AC 74 ms
71,308 KB
testcase_31 AC 75 ms
71,276 KB
testcase_32 AC 74 ms
70,980 KB
testcase_33 AC 79 ms
75,700 KB
testcase_34 AC 76 ms
71,100 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(
        """
10
3 8 9 7 2 2 10 10 35 5



        """
            .strip().split("\n"))
    input = lambda: next(example)



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

# example()

def test(x):
    return A[i-x]+A[-1-x]-2*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