結果

問題 No.972 選び方のスコア
ユーザー NoneNone
提出日時 2021-03-25 22:39:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 917 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 116,156 KB
最終ジャッジ日時 2023-08-18 05:14:19
合計ジャッジ時間 9,495 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 242 ms
115,856 KB
testcase_01 AC 240 ms
115,588 KB
testcase_02 AC 239 ms
115,504 KB
testcase_03 AC 168 ms
99,216 KB
testcase_04 AC 239 ms
114,500 KB
testcase_05 WA -
testcase_06 AC 236 ms
114,152 KB
testcase_07 AC 207 ms
101,132 KB
testcase_08 AC 188 ms
114,224 KB
testcase_09 AC 188 ms
113,848 KB
testcase_10 AC 179 ms
113,964 KB
testcase_11 AC 179 ms
114,304 KB
testcase_12 AC 210 ms
114,704 KB
testcase_13 AC 197 ms
114,452 KB
testcase_14 AC 214 ms
114,948 KB
testcase_15 AC 234 ms
115,656 KB
testcase_16 AC 241 ms
116,156 KB
testcase_17 AC 240 ms
115,928 KB
testcase_18 AC 73 ms
71,096 KB
testcase_19 AC 238 ms
106,476 KB
testcase_20 AC 241 ms
106,388 KB
testcase_21 AC 241 ms
106,256 KB
testcase_22 WA -
testcase_23 AC 238 ms
106,724 KB
testcase_24 AC 242 ms
106,516 KB
testcase_25 AC 72 ms
71,320 KB
testcase_26 AC 71 ms
71,212 KB
testcase_27 AC 71 ms
70,980 KB
testcase_28 AC 70 ms
71,248 KB
testcase_29 AC 72 ms
71,296 KB
testcase_30 AC 72 ms
71,332 KB
testcase_31 AC 70 ms
71,200 KB
testcase_32 AC 72 ms
71,456 KB
testcase_33 AC 77 ms
75,532 KB
testcase_34 AC 74 ms
71,284 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+1),test)
    S=acc[i+1]-acc[i-k] +acc[N]-acc[N-k] -m*(2*k+1)
    res=max(res,S)
print(res)
0