結果

問題 No.972 選び方のスコア
ユーザー ntudantuda
提出日時 2021-11-10 23:00:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 683 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 108,432 KB
最終ジャッジ日時 2023-08-13 21:55:31
合計ジャッジ時間 10,288 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 310 ms
103,992 KB
testcase_01 AC 309 ms
103,928 KB
testcase_02 AC 308 ms
103,588 KB
testcase_03 AC 216 ms
96,148 KB
testcase_04 AC 305 ms
103,088 KB
testcase_05 AC 306 ms
102,716 KB
testcase_06 AC 312 ms
102,836 KB
testcase_07 AC 278 ms
104,128 KB
testcase_08 AC 267 ms
102,376 KB
testcase_09 AC 262 ms
101,892 KB
testcase_10 AC 230 ms
102,032 KB
testcase_11 AC 229 ms
102,220 KB
testcase_12 AC 312 ms
102,588 KB
testcase_13 AC 315 ms
102,996 KB
testcase_14 AC 311 ms
102,792 KB
testcase_15 AC 314 ms
104,324 KB
testcase_16 AC 312 ms
104,636 KB
testcase_17 AC 298 ms
104,440 KB
testcase_18 AC 67 ms
71,276 KB
testcase_19 AC 309 ms
108,260 KB
testcase_20 AC 310 ms
107,932 KB
testcase_21 AC 309 ms
107,972 KB
testcase_22 AC 294 ms
107,668 KB
testcase_23 AC 310 ms
107,956 KB
testcase_24 AC 307 ms
108,432 KB
testcase_25 AC 67 ms
71,636 KB
testcase_26 AC 67 ms
71,416 KB
testcase_27 AC 68 ms
71,148 KB
testcase_28 AC 68 ms
71,352 KB
testcase_29 AC 67 ms
71,568 KB
testcase_30 AC 68 ms
71,348 KB
testcase_31 AC 69 ms
71,148 KB
testcase_32 AC 68 ms
71,468 KB
testcase_33 AC 76 ms
75,932 KB
testcase_34 AC 69 ms
71,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

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

if N < 3:
    print(0)
    sys.exit()
A.sort()

B = [0] * (N + 1)
for i in range(N):
    B[i + 1] = B[i] + A[i]

def g(x, y):
    return B[N] - B[N - y] + B[x] - B[x - y] - (2 * y) * A[x]

def f(x):
    lb = 1
    ub = min(x, N - x - 1)
    t1 = (ub + 2 * lb) // 3
    t2 = (2 * ub + lb) // 3

    while ub - lb > 3:  # ???
        b, c = g(x, t1), g(x, t2)
        if b < c:
            lb = t1
        else:
            ub = t2
        t1 = (ub + 2 * lb) // 3
        t2 = (2 * ub + lb) // 3
    return (max(g(x, lb), g(x, t1), g(x, t2), g(x, ub)))

ans = 0
for i in range(1,N-1):
    ans = max(ans,f(i))
print(ans)
0