結果

問題 No.972 選び方のスコア
ユーザー hedwig100hedwig100
提出日時 2020-04-26 12:34:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 883 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 39,468 KB
最終ジャッジ日時 2023-08-10 14:14:10
合計ジャッジ時間 13,540 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 399 ms
37,808 KB
testcase_01 AC 400 ms
38,096 KB
testcase_02 AC 377 ms
36,380 KB
testcase_03 AC 189 ms
22,948 KB
testcase_04 AC 410 ms
37,716 KB
testcase_05 AC 409 ms
37,516 KB
testcase_06 AC 395 ms
37,592 KB
testcase_07 AC 286 ms
30,464 KB
testcase_08 AC 291 ms
37,964 KB
testcase_09 AC 285 ms
36,824 KB
testcase_10 AC 287 ms
38,028 KB
testcase_11 AC 287 ms
37,708 KB
testcase_12 AC 306 ms
37,884 KB
testcase_13 AC 304 ms
37,800 KB
testcase_14 AC 303 ms
37,888 KB
testcase_15 AC 315 ms
37,524 KB
testcase_16 AC 312 ms
37,928 KB
testcase_17 AC 315 ms
37,884 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 16 ms
8,060 KB
testcase_26 AC 16 ms
8,144 KB
testcase_27 AC 16 ms
8,064 KB
testcase_28 AC 16 ms
8,044 KB
testcase_29 AC 15 ms
8,088 KB
testcase_30 AC 16 ms
7,988 KB
testcase_31 AC 16 ms
8,200 KB
testcase_32 AC 15 ms
8,084 KB
testcase_33 AC 16 ms
8,224 KB
testcase_34 AC 16 ms
8,284 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//2):
        ans = max(ans,cuml[i + 1] + cumr[n - i] - a[i]*(2*i + 1))
    for i in range(n//2,n):
        ans = max(ans,cumr[2*i - n + 1] - a[i]*(2*n - 2*i - 1))
    
    for i in range(1,(n + 1)//2):
        ans = max(ans,cuml[i + 1] + cumr[n - i + 1] - (a[i] + a[i - 1])*i)
    for i in range((n + 1)//2,n):
        ans = max(ans,cumr[2*i - n] - (a[i] + a[i - 1])*(n - i))
    print(ans)
if __name__=='__main__':
    main()
0