結果

問題 No.972 選び方のスコア
ユーザー hedwig100hedwig100
提出日時 2020-04-26 13:10:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,156 ms / 2,000 ms
コード長 826 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 37,880 KB
最終ジャッジ日時 2023-08-10 17:27:58
合計ジャッジ時間 27,917 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,134 ms
37,880 KB
testcase_01 AC 1,156 ms
37,772 KB
testcase_02 AC 1,076 ms
36,384 KB
testcase_03 AC 530 ms
22,768 KB
testcase_04 AC 1,108 ms
37,680 KB
testcase_05 AC 1,131 ms
37,572 KB
testcase_06 AC 1,128 ms
37,492 KB
testcase_07 AC 839 ms
30,232 KB
testcase_08 AC 970 ms
37,684 KB
testcase_09 AC 917 ms
36,644 KB
testcase_10 AC 863 ms
37,796 KB
testcase_11 AC 823 ms
37,780 KB
testcase_12 AC 920 ms
37,728 KB
testcase_13 AC 995 ms
37,748 KB
testcase_14 AC 914 ms
37,828 KB
testcase_15 AC 1,008 ms
37,344 KB
testcase_16 AC 1,011 ms
37,816 KB
testcase_17 AC 997 ms
37,704 KB
testcase_18 AC 15 ms
7,808 KB
testcase_19 AC 1,117 ms
37,788 KB
testcase_20 AC 1,103 ms
37,788 KB
testcase_21 AC 1,128 ms
37,816 KB
testcase_22 AC 1,074 ms
36,316 KB
testcase_23 AC 1,096 ms
37,752 KB
testcase_24 AC 1,127 ms
37,840 KB
testcase_25 AC 15 ms
7,736 KB
testcase_26 AC 15 ms
7,904 KB
testcase_27 AC 14 ms
7,900 KB
testcase_28 AC 15 ms
7,844 KB
testcase_29 AC 16 ms
7,840 KB
testcase_30 AC 15 ms
7,768 KB
testcase_31 AC 16 ms
7,800 KB
testcase_32 AC 16 ms
7,936 KB
testcase_33 AC 15 ms
7,804 KB
testcase_34 AC 14 ms
7,812 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