結果

問題 No.972 選び方のスコア
ユーザー NoneNone
提出日時 2021-03-25 21:57:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 726 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 116,008 KB
最終ジャッジ日時 2023-08-18 04:35:08
合計ジャッジ時間 7,911 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 213 ms
115,932 KB
testcase_01 AC 219 ms
115,752 KB
testcase_02 AC 211 ms
115,428 KB
testcase_03 AC 157 ms
100,084 KB
testcase_04 AC 214 ms
114,700 KB
testcase_05 AC 216 ms
114,324 KB
testcase_06 AC 213 ms
114,336 KB
testcase_07 AC 187 ms
101,536 KB
testcase_08 AC 186 ms
114,424 KB
testcase_09 AC 177 ms
114,004 KB
testcase_10 AC 177 ms
114,408 KB
testcase_11 AC 178 ms
114,264 KB
testcase_12 AC 192 ms
114,368 KB
testcase_13 AC 195 ms
114,716 KB
testcase_14 AC 192 ms
114,276 KB
testcase_15 AC 197 ms
115,744 KB
testcase_16 AC 192 ms
116,008 KB
testcase_17 AC 193 ms
115,808 KB
testcase_18 AC 75 ms
71,416 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 76 ms
71,456 KB
testcase_26 AC 72 ms
71,400 KB
testcase_27 AC 74 ms
71,272 KB
testcase_28 AC 75 ms
71,572 KB
testcase_29 AC 75 ms
71,308 KB
testcase_30 AC 74 ms
71,280 KB
testcase_31 AC 74 ms
71,380 KB
testcase_32 AC 73 ms
71,500 KB
testcase_33 AC 79 ms
75,580 KB
testcase_34 AC 76 ms
71,384 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

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

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-1-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