結果

問題 No.972 選び方のスコア
ユーザー tcltktcltk
提出日時 2021-09-24 06:14:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 416 ms / 2,000 ms
コード長 1,271 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 133,732 KB
最終ジャッジ日時 2023-09-18 20:08:41
合計ジャッジ時間 14,522 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 397 ms
133,564 KB
testcase_01 AC 398 ms
133,264 KB
testcase_02 AC 403 ms
132,840 KB
testcase_03 AC 318 ms
107,996 KB
testcase_04 AC 394 ms
132,760 KB
testcase_05 AC 389 ms
132,220 KB
testcase_06 AC 392 ms
132,520 KB
testcase_07 AC 353 ms
123,292 KB
testcase_08 AC 375 ms
131,400 KB
testcase_09 AC 363 ms
130,348 KB
testcase_10 AC 321 ms
131,232 KB
testcase_11 AC 324 ms
131,996 KB
testcase_12 AC 394 ms
131,896 KB
testcase_13 AC 376 ms
132,036 KB
testcase_14 AC 392 ms
131,696 KB
testcase_15 AC 401 ms
132,748 KB
testcase_16 AC 377 ms
133,732 KB
testcase_17 AC 393 ms
133,656 KB
testcase_18 AC 211 ms
80,932 KB
testcase_19 AC 416 ms
132,028 KB
testcase_20 AC 393 ms
131,932 KB
testcase_21 AC 404 ms
131,896 KB
testcase_22 AC 384 ms
132,392 KB
testcase_23 AC 398 ms
131,780 KB
testcase_24 AC 408 ms
132,240 KB
testcase_25 AC 211 ms
80,956 KB
testcase_26 AC 213 ms
80,708 KB
testcase_27 AC 216 ms
80,996 KB
testcase_28 AC 211 ms
81,040 KB
testcase_29 AC 221 ms
80,844 KB
testcase_30 AC 220 ms
80,832 KB
testcase_31 AC 223 ms
80,876 KB
testcase_32 AC 212 ms
80,744 KB
testcase_33 AC 232 ms
83,780 KB
testcase_34 AC 217 ms
80,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]

# sys.setrecursionlimit(1000000)

# _INPUT = """5
# 1 2 3 4 5
# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**10

def check1(i, k):
    v = A[i-k] + A[N-k] - A[i]*2
    return (v > 0)

def check2(i, k):
    v = A[i-k] + A[N-k] - (A[i] + A[i+1])
    return (v > 0)


N = int(input())
A = list(map(int, input().split()))
A.sort()
S = [0] + list(itertools.accumulate(A))

score_max = 0

# 奇数個数の部分列
for i in range(1, N-1):
    ok = 0
    ng = min(i, N-1-i) + 1
    while ng - ok > 1:
        mid = (ok+ng)//2
        if check1(i, mid):
            ok = mid
        else:
            ng = mid
    k = ok
    score = (S[i]-S[i-k]) + (S[N]-S[N-k]) - 2*k*A[i]
    score_max = max(score_max, score)

# 偶数個数の部分列
for i in range(1, N-2):
    ok = 0
    ng = min(i, N-2-i) + 1
    while ng - ok > 1:
        mid = (ok+ng)//2
        if check2(i, mid):
            ok = mid
        else:
            ng = mid
    k = ok
    score = (S[i]-S[i-k]) + (S[N]-S[N-k]) - k*(A[i]+A[i+1])
    score_max = max(score_max, score)



print(score_max)

0