結果
| 問題 |
No.972 選び方のスコア
|
| コンテスト | |
| ユーザー |
ntuda
|
| 提出日時 | 2021-11-10 22:59:36 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 766 bytes |
| コンパイル時間 | 297 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 1,134,832 KB |
| 最終ジャッジ日時 | 2024-11-21 16:01:28 |
| 合計ジャッジ時間 | 79,473 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 TLE * 1 MLE * 24 |
ソースコード
import sys
from functools import lru_cache
N = int(input())
A = list(map(int, input().split()))
if N < 3:
print(0)
sys.exit()
A.sort()
B = [0] * (N + 1)
for i in range(N):
B[i + 1] = B[i] + A[i]
@lru_cache(maxsize=None)
def g(x, y):
return B[N] - B[N - y] + B[x] - B[x - y] - (2 * y) * A[x]
#@lru_cache(maxsize=None)
def f(x):
lb = 1
ub = min(x, N - x - 1)
t1 = (ub + 2 * lb) // 3
t2 = (2 * ub + lb) // 3
while ub - lb > 3: # ???
b, c = g(x, t1), g(x, t2)
if b < c:
lb = t1
else:
ub = t2
t1 = (ub + 2 * lb) // 3
t2 = (2 * ub + lb) // 3
return (max(g(x, lb), g(x, t1), g(x, t2), g(x, ub)))
ans = 0
for i in range(1,N-1):
ans = max(ans,f(i))
print(ans)
ntuda