結果

問題 No.972 選び方のスコア
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-25 17:58:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 458 bytes
コンパイル時間 1,084 ms
コンパイル使用メモリ 81,768 KB
実行使用メモリ 108,384 KB
最終ジャッジ日時 2023-10-23 17:30:02
合計ジャッジ時間 8,519 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
101,752 KB
testcase_01 AC 133 ms
101,476 KB
testcase_02 AC 122 ms
107,056 KB
testcase_03 AC 79 ms
85,516 KB
testcase_04 AC 124 ms
108,088 KB
testcase_05 AC 125 ms
107,824 KB
testcase_06 AC 124 ms
107,824 KB
testcase_07 AC 108 ms
101,624 KB
testcase_08 AC 91 ms
106,828 KB
testcase_09 AC 91 ms
106,384 KB
testcase_10 AC 88 ms
106,828 KB
testcase_11 AC 94 ms
101,536 KB
testcase_12 AC 101 ms
101,560 KB
testcase_13 AC 100 ms
101,560 KB
testcase_14 AC 100 ms
101,560 KB
testcase_15 AC 113 ms
101,392 KB
testcase_16 AC 109 ms
101,584 KB
testcase_17 AC 108 ms
101,584 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 43 ms
53,496 KB
testcase_26 AC 35 ms
53,496 KB
testcase_27 AC 36 ms
53,496 KB
testcase_28 AC 41 ms
53,496 KB
testcase_29 AC 34 ms
53,496 KB
testcase_30 AC 35 ms
53,496 KB
testcase_31 AC 35 ms
53,496 KB
testcase_32 AC 34 ms
53,496 KB
testcase_33 AC 35 ms
53,496 KB
testcase_34 AC 35 ms
53,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ans = 0
X = 0
Y = 0
size = 0

i = 0
j = N - 1
while i + 1 < j:
    X += A[i]
    Y += A[j]
    size += 2
    # 奇数個選ぶ場合
    med = A[i + 1]
    tmp = X + Y + med - med * (size + 1)
    ans = max(ans, tmp)

    # 偶数
    if i + 2 < j:
        med = A[i + 1] + A[i + 2]
        tmp = X + Y + med - med * (size + 2) // 2
        ans = max(ans, tmp)

    i += 1
    j -= 1

print(ans)
0