結果

問題 No.972 選び方のスコア
ユーザー titiatitia
提出日時 2020-01-17 22:49:34
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 539 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 117,076 KB
最終ジャッジ日時 2023-09-08 05:53:32
合計ジャッジ時間 8,027 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 216 ms
116,548 KB
testcase_01 AC 215 ms
116,760 KB
testcase_02 AC 211 ms
116,104 KB
testcase_03 AC 142 ms
98,664 KB
testcase_04 AC 209 ms
115,868 KB
testcase_05 AC 211 ms
115,604 KB
testcase_06 AC 212 ms
115,548 KB
testcase_07 AC 173 ms
102,708 KB
testcase_08 AC 178 ms
115,276 KB
testcase_09 AC 175 ms
114,852 KB
testcase_10 AC 154 ms
115,036 KB
testcase_11 AC 153 ms
114,944 KB
testcase_12 AC 199 ms
115,212 KB
testcase_13 AC 185 ms
115,196 KB
testcase_14 AC 194 ms
115,160 KB
testcase_15 AC 192 ms
116,292 KB
testcase_16 AC 181 ms
117,076 KB
testcase_17 AC 187 ms
116,864 KB
testcase_18 AC 68 ms
71,348 KB
testcase_19 AC 198 ms
108,740 KB
testcase_20 AC 199 ms
107,568 KB
testcase_21 AC 200 ms
108,488 KB
testcase_22 AC 199 ms
107,340 KB
testcase_23 AC 203 ms
108,480 KB
testcase_24 AC 199 ms
107,904 KB
testcase_25 AC 68 ms
71,124 KB
testcase_26 AC 71 ms
71,276 KB
testcase_27 AC 69 ms
71,284 KB
testcase_28 AC 70 ms
71,316 KB
testcase_29 AC 70 ms
71,328 KB
testcase_30 AC 69 ms
71,284 KB
testcase_31 AC 69 ms
71,220 KB
testcase_32 AC 68 ms
71,280 KB
testcase_33 AC 71 ms
75,528 KB
testcase_34 AC 69 ms
71,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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