結果
| 問題 |
No.972 選び方のスコア
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-18 13:21:16 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,560 ms / 2,000 ms |
| コード長 | 950 bytes |
| コンパイル時間 | 262 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 32,048 KB |
| 最終ジャッジ日時 | 2024-12-14 01:47:40 |
| 合計ジャッジ時間 | 38,251 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#!/usr/bin/env python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
N, *A = map(int, read().split())
A = sorted(A)
Acum = tuple(itertools.accumulate(A))
def solve(mid):
left = mid
right = N - 1 - mid
n = min(left, right)
if n == 0:
return 0
LR = mid - 1
LL = LR - n + 1
RR = N - 1
RL = RR - n + 1
left = -1 # とらない
right = n # とる
while left + 1 < right:
x = (left + right) // 2
if A[LL + x] + A[RL + x] <= 2 * A[mid]:
left = x
else:
right = x
if right == n + 1:
return 0
i = left
SL = Acum[LR]
if LL + i >= 0:
SL -= Acum[LL + i]
SR = Acum[RR] - Acum[RL + i]
S = SL + SR + A[mid]
n_elem = (LR - LL - left) * 2 + 1
return S - A[mid] * n_elem
answer = max(solve(i) for i in range(N))
print(answer)
maspy