結果

問題 No.972 選び方のスコア
ユーザー hedwig100hedwig100
提出日時 2020-04-26 13:00:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,286 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 11,076 KB
実行使用メモリ 39,368 KB
最終ジャッジ日時 2023-08-10 17:04:22
合計ジャッジ時間 51,467 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 AC 1,949 ms
36,660 KB
testcase_03 AC 922 ms
22,888 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 AC 1,524 ms
30,736 KB
testcase_08 AC 1,840 ms
38,072 KB
testcase_09 AC 1,780 ms
36,848 KB
testcase_10 AC 1,675 ms
38,128 KB
testcase_11 AC 1,675 ms
37,912 KB
testcase_12 AC 1,810 ms
37,960 KB
testcase_13 AC 1,933 ms
38,044 KB
testcase_14 AC 1,783 ms
37,992 KB
testcase_15 AC 1,950 ms
37,524 KB
testcase_16 AC 1,909 ms
37,848 KB
testcase_17 AC 1,967 ms
38,120 KB
testcase_18 AC 15 ms
8,184 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 AC 16 ms
8,096 KB
testcase_26 AC 15 ms
8,260 KB
testcase_27 AC 16 ms
8,140 KB
testcase_28 AC 16 ms
8,176 KB
testcase_29 AC 16 ms
8,256 KB
testcase_30 AC 16 ms
8,160 KB
testcase_31 AC 16 ms
8,148 KB
testcase_32 AC 15 ms
8,104 KB
testcase_33 AC 16 ms
8,260 KB
testcase_34 AC 15 ms
8,156 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):
        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))
    
    #要素数が偶数の場合
    for i in range(1,n):
        max_len = min(i - 1,n - i - 1)
        r = max_len + 1
        l = 0
        while r - l > 1:
            mid = (r + l)//2
            if a[i - mid - 1] + a[n - mid] > a[i - 1] + a[i]:
                l = mid
            else:
                r = mid
        ans = max(ans,cuml[i + 1] - cuml[i - l - 1] + cumr[n - l] - (a[i] + a[i - 1])*(l + 1))
    
    print(ans)
if __name__=='__main__':
    main()
0