結果

問題 No.972 選び方のスコア
コンテスト
ユーザー titia
提出日時 2020-01-17 22:49:34
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 151 ms / 2,000 ms
+ 188µs
コード長 539 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 244 ms
コンパイル使用メモリ 96,100 KB
実行使用メモリ 133,248 KB
最終ジャッジ日時 2026-07-30 03:49:38
合計ジャッジ時間 6,755 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

N=int(input())
A=sorted(map(int,input().split()))

from itertools import accumulate
S=[0]+list(accumulate(A))

if N<=2:
    print(0)
    sys.exit()

ANS=0
for i in range(1,N-1):
    OK=0
    NG=i+1

    while NG-OK>1:
        mid=(OK+NG)//2

        if mid>=1 and A[-mid]-A[i]>A[i]-A[i-mid]:
            OK=mid
        else:
            NG=mid

    if OK==0:
        continue

    #print(i,OK,S[-1]-S[-OK-1]+S[i+1]-S[i-OK]-A[i]*(2*OK+1))
    ANS=max(ANS,S[-1]-S[-OK-1]+S[i+1]-S[i-OK]-A[i]*(2*OK+1))

print(ANS)

    
    
    
0