結果
| 問題 |
No.972 選び方のスコア
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-25 22:39:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 917 bytes |
| コンパイル時間 | 215 ms |
| コンパイル使用メモリ | 82,680 KB |
| 実行使用メモリ | 120,412 KB |
| 最終ジャッジ日時 | 2024-11-27 08:06:20 |
| 合計ジャッジ時間 | 6,632 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 WA * 2 |
ソースコード
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):
return A[i-x]+A[-1-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+1),test)
S=acc[i+1]-acc[i-k] +acc[N]-acc[N-k] -m*(2*k+1)
res=max(res,S)
print(res)