結果

問題 No.972 選び方のスコア
ユーザー NoneNone
提出日時 2021-03-25 22:57:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 945 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 86,748 KB
実行使用メモリ 116,152 KB
最終ジャッジ日時 2023-08-18 05:31:05
合計ジャッジ時間 8,741 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 239 ms
115,976 KB
testcase_01 AC 237 ms
116,072 KB
testcase_02 AC 235 ms
115,536 KB
testcase_03 AC 170 ms
99,936 KB
testcase_04 AC 239 ms
114,400 KB
testcase_05 AC 233 ms
114,052 KB
testcase_06 AC 234 ms
114,348 KB
testcase_07 AC 204 ms
101,060 KB
testcase_08 AC 206 ms
114,340 KB
testcase_09 AC 204 ms
114,060 KB
testcase_10 AC 174 ms
114,088 KB
testcase_11 AC 178 ms
114,108 KB
testcase_12 AC 189 ms
114,880 KB
testcase_13 AC 228 ms
114,544 KB
testcase_14 AC 192 ms
114,644 KB
testcase_15 AC 236 ms
115,708 KB
testcase_16 AC 230 ms
116,152 KB
testcase_17 AC 230 ms
115,812 KB
testcase_18 AC 74 ms
71,172 KB
testcase_19 AC 237 ms
106,536 KB
testcase_20 AC 234 ms
106,192 KB
testcase_21 AC 240 ms
106,464 KB
testcase_22 AC 220 ms
105,988 KB
testcase_23 AC 233 ms
106,236 KB
testcase_24 AC 235 ms
106,648 KB
testcase_25 AC 74 ms
71,324 KB
testcase_26 AC 74 ms
71,116 KB
testcase_27 AC 73 ms
71,308 KB
testcase_28 AC 74 ms
71,356 KB
testcase_29 AC 73 ms
71,196 KB
testcase_30 AC 75 ms
70,960 KB
testcase_31 AC 74 ms
71,252 KB
testcase_32 AC 75 ms
71,252 KB
testcase_33 AC 80 ms
75,652 KB
testcase_34 AC 75 ms
71,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def binary_search_int(ok, ng, test):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if test(mid):
            ok = mid
        else:
            ng = mid
    return ok

def example():
    global input
    example = iter(
        """
10
3 8 9 7 2 2 10 10 35 5

        """
            .strip().split("\n"))
    input = lambda: next(example)



##############################################################
import sys
input = sys.stdin.readline

# example()

def test(x):
    if x==0: return True
    return A[i-x]+A[N-x]-2*m>0

N=int(input())
A=list(map(int, input().split()))
A.sort()
acc=[0]
for a in A:
    acc.append(acc[-1]+a)

res=0
for i in range(N):
    m=A[i]
    k=binary_search_int(0,min(i+1,N-i),test)
    S=acc[i+1]-acc[i-k] +acc[N]-acc[N-k] -m*(2*k+1)
    if res<S:
        res=S
print(res)
0