結果

問題 No.972 選び方のスコア
ユーザー AEnAEn
提出日時 2023-04-17 21:55:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 418 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,300 KB
実行使用メモリ 110,592 KB
最終ジャッジ日時 2024-04-21 00:00:05
合計ジャッジ時間 6,756 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 189 ms
101,944 KB
testcase_01 AC 182 ms
102,344 KB
testcase_02 AC 176 ms
107,392 KB
testcase_03 AC 112 ms
89,344 KB
testcase_04 AC 178 ms
110,592 KB
testcase_05 AC 177 ms
110,336 KB
testcase_06 AC 178 ms
109,952 KB
testcase_07 AC 154 ms
104,320 KB
testcase_08 AC 143 ms
108,544 KB
testcase_09 AC 144 ms
108,672 KB
testcase_10 AC 120 ms
108,672 KB
testcase_11 AC 126 ms
101,760 KB
testcase_12 AC 165 ms
101,888 KB
testcase_13 AC 158 ms
102,144 KB
testcase_14 AC 168 ms
101,760 KB
testcase_15 AC 168 ms
101,888 KB
testcase_16 AC 165 ms
102,328 KB
testcase_17 AC 164 ms
102,016 KB
testcase_18 AC 39 ms
51,712 KB
testcase_19 AC 179 ms
110,208 KB
testcase_20 AC 179 ms
110,208 KB
testcase_21 AC 180 ms
109,996 KB
testcase_22 AC 172 ms
110,336 KB
testcase_23 AC 179 ms
110,008 KB
testcase_24 AC 178 ms
109,824 KB
testcase_25 AC 39 ms
52,096 KB
testcase_26 AC 38 ms
52,352 KB
testcase_27 AC 39 ms
51,968 KB
testcase_28 AC 38 ms
52,096 KB
testcase_29 AC 39 ms
51,712 KB
testcase_30 AC 38 ms
51,840 KB
testcase_31 AC 38 ms
52,096 KB
testcase_32 AC 40 ms
51,968 KB
testcase_33 AC 43 ms
58,368 KB
testcase_34 AC 39 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
a = list(map(int, input().split()))
a.sort()

b = [0]*(N+1)
for i in range(1,N+1):
    b[i] += b[i-1]+a[i-1]
res = 0
for i in range(1,N-1):
    ok,ng = 0,min(i,N-1-i)+1
    while ng-ok>1:
        mid = (ok+ng)//2
        if b[i-mid+1]-b[i-mid]+b[N-mid+1]-b[N-mid]-2*a[i]>0:
            ok = mid
        else:
            ng = mid
    res = max(res,b[i]-b[i-ok]+b[N]-b[N-ok]-2*ok*a[i])
print(res)
    
0