結果

問題 No.972 選び方のスコア
ユーザー hedwig100hedwig100
提出日時 2020-04-26 13:10:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,348 ms / 2,000 ms
コード長 826 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 41,892 KB
最終ジャッジ日時 2024-04-28 10:53:27
合計ジャッジ時間 31,755 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,348 ms
40,724 KB
testcase_01 AC 1,312 ms
40,724 KB
testcase_02 AC 1,320 ms
38,976 KB
testcase_03 AC 596 ms
25,340 KB
testcase_04 AC 1,297 ms
40,312 KB
testcase_05 AC 1,325 ms
40,180 KB
testcase_06 AC 1,288 ms
40,184 KB
testcase_07 AC 994 ms
33,148 KB
testcase_08 AC 1,152 ms
40,824 KB
testcase_09 AC 1,162 ms
39,456 KB
testcase_10 AC 1,021 ms
40,696 KB
testcase_11 AC 975 ms
40,412 KB
testcase_12 AC 1,111 ms
40,616 KB
testcase_13 AC 1,326 ms
40,488 KB
testcase_14 AC 1,071 ms
40,628 KB
testcase_15 AC 1,217 ms
40,088 KB
testcase_16 AC 1,245 ms
40,464 KB
testcase_17 AC 1,260 ms
40,492 KB
testcase_18 AC 25 ms
10,752 KB
testcase_19 AC 1,293 ms
40,504 KB
testcase_20 AC 1,256 ms
40,524 KB
testcase_21 AC 1,305 ms
40,612 KB
testcase_22 AC 1,246 ms
38,872 KB
testcase_23 AC 1,248 ms
41,800 KB
testcase_24 AC 1,264 ms
41,892 KB
testcase_25 AC 28 ms
10,624 KB
testcase_26 AC 27 ms
10,880 KB
testcase_27 AC 27 ms
10,624 KB
testcase_28 AC 28 ms
10,880 KB
testcase_29 AC 26 ms
10,624 KB
testcase_30 AC 28 ms
10,752 KB
testcase_31 AC 25 ms
10,624 KB
testcase_32 AC 24 ms
10,880 KB
testcase_33 AC 25 ms
10,624 KB
testcase_34 AC 25 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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))
    
    print(ans)
if __name__=='__main__':
    main()
0