結果

問題 No.972 選び方のスコア
ユーザー NoneNone
提出日時 2021-03-25 22:39:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 915 bytes
コンパイル時間 1,605 ms
コンパイル使用メモリ 81,664 KB
実行使用メモリ 120,576 KB
最終ジャッジ日時 2024-11-27 08:08:08
合計ジャッジ時間 7,119 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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