結果

問題 No.972 選び方のスコア
ユーザー hedwig100hedwig100
提出日時 2020-04-26 13:00:51
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 1,522 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 110,944 KB
最終ジャッジ日時 2023-08-10 17:06:23
合計ジャッジ時間 9,529 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 243 ms
109,672 KB
testcase_01 AC 253 ms
109,800 KB
testcase_02 AC 239 ms
108,800 KB
testcase_03 AC 163 ms
93,856 KB
testcase_04 AC 239 ms
105,512 KB
testcase_05 AC 231 ms
105,516 KB
testcase_06 AC 230 ms
105,488 KB
testcase_07 AC 218 ms
98,548 KB
testcase_08 AC 217 ms
107,756 KB
testcase_09 AC 221 ms
105,864 KB
testcase_10 AC 174 ms
107,740 KB
testcase_11 AC 164 ms
107,924 KB
testcase_12 AC 283 ms
109,276 KB
testcase_13 AC 248 ms
108,992 KB
testcase_14 AC 277 ms
108,952 KB
testcase_15 AC 248 ms
108,984 KB
testcase_16 AC 233 ms
110,944 KB
testcase_17 AC 235 ms
110,628 KB
testcase_18 AC 72 ms
71,504 KB
testcase_19 AC 251 ms
103,488 KB
testcase_20 AC 253 ms
103,628 KB
testcase_21 AC 248 ms
103,708 KB
testcase_22 AC 225 ms
103,824 KB
testcase_23 AC 255 ms
103,432 KB
testcase_24 AC 256 ms
103,588 KB
testcase_25 AC 69 ms
71,356 KB
testcase_26 AC 68 ms
71,216 KB
testcase_27 AC 68 ms
71,040 KB
testcase_28 AC 69 ms
71,332 KB
testcase_29 AC 69 ms
71,560 KB
testcase_30 AC 70 ms
71,296 KB
testcase_31 AC 70 ms
71,252 KB
testcase_32 AC 70 ms
71,508 KB
testcase_33 AC 72 ms
75,500 KB
testcase_34 AC 68 ms
71,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 9
MOD = 10 **9 + 7
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from heapq import heapify,heappop,heappush

def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    cuml = [0] * (n + 1)
    cumr = [0] * (n + 1)
    for i in range(n):
        cuml[i + 1] = cuml[i] + a[i]
    for i in range(n - 1,-1,-1):
        cumr[i] = cumr[i + 1] + a[i]
    
    ans = -INF
    #要素数が奇数の場合
    for i in range(n):
        max_len = min(i,n - i - 1)
        r = max_len + 1
        l = 0
        while r - l > 1:
            mid = (r + l)//2
            if a[i - mid] + a[n - mid] > 2*a[i]:
                l = mid
            else:
                r = mid
        ans = max(ans,cuml[i + 1] - cuml[i - l] + cumr[n - l] - a[i]*(2*l + 1))
    
    #要素数が偶数の場合
    for i in range(1,n):
        max_len = min(i - 1,n - i - 1)
        r = max_len + 1
        l = 0
        while r - l > 1:
            mid = (r + l)//2
            if a[i - mid - 1] + a[n - mid] > a[i - 1] + a[i]:
                l = mid
            else:
                r = mid
        ans = max(ans,cuml[i + 1] - cuml[i - l - 1] + cumr[n - l] - (a[i] + a[i - 1])*(l + 1))
    
    print(ans)
if __name__=='__main__':
    main()
0