結果

問題 No.972 選び方のスコア
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-11-09 11:03:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 842 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 118,492 KB
最終ジャッジ日時 2023-11-09 11:03:56
合計ジャッジ時間 8,861 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 183 ms
118,312 KB
testcase_01 AC 190 ms
118,328 KB
testcase_02 AC 210 ms
118,392 KB
testcase_03 AC 118 ms
96,752 KB
testcase_04 AC 177 ms
115,280 KB
testcase_05 AC 177 ms
115,024 KB
testcase_06 AC 177 ms
115,024 KB
testcase_07 AC 179 ms
115,180 KB
testcase_08 AC 151 ms
115,696 KB
testcase_09 AC 173 ms
114,004 KB
testcase_10 AC 121 ms
115,684 KB
testcase_11 AC 122 ms
116,616 KB
testcase_12 AC 144 ms
116,728 KB
testcase_13 AC 138 ms
116,852 KB
testcase_14 AC 146 ms
116,732 KB
testcase_15 AC 166 ms
118,128 KB
testcase_16 AC 185 ms
118,492 KB
testcase_17 AC 159 ms
118,244 KB
testcase_18 AC 45 ms
55,724 KB
testcase_19 AC 188 ms
114,872 KB
testcase_20 AC 188 ms
114,628 KB
testcase_21 AC 188 ms
114,528 KB
testcase_22 AC 191 ms
115,184 KB
testcase_23 AC 214 ms
114,496 KB
testcase_24 AC 187 ms
114,768 KB
testcase_25 AC 44 ms
55,724 KB
testcase_26 AC 44 ms
55,724 KB
testcase_27 AC 45 ms
55,724 KB
testcase_28 AC 45 ms
55,724 KB
testcase_29 AC 46 ms
55,724 KB
testcase_30 AC 51 ms
55,724 KB
testcase_31 AC 45 ms
55,724 KB
testcase_32 AC 54 ms
55,724 KB
testcase_33 AC 46 ms
57,836 KB
testcase_34 AC 45 ms
55,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
A.sort()
S = list(accumulate([0]+A))
ans = 0
for i in range(1,N-1):
    
    m = A[i]
    
    l = min(i-0,N-i-1)
    if (A[i-l] + A[N-l]) >= 2*m:
        
        val = S[i] - S[i-l] + S[-1] - S[-1-l] - 2*l*m
        
        ans = max(ans,val)
        continue
    elif A[i-1]+A[N-1] < 2*m:
        continue
    else:
        
        y = l
        x = 1
        while y - x > 1:
            
            mid = (y+x)//2
            
            if (A[i-mid] + A[N-mid]) >= 2*m:
                x = mid
            else:
                y = mid
        val = S[i] - S[i - x] + S[-1] - S[-1-x] - 2*x*m
        ans = max(ans,val)
print(ans)
            
0