結果
| 問題 |
No.972 選び方のスコア
|
| コンテスト | |
| ユーザー |
rlangevin
|
| 提出日時 | 2024-04-09 12:25:13 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 218 ms / 2,000 ms |
| コード長 | 606 bytes |
| コンパイル時間 | 629 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 111,872 KB |
| 最終ジャッジ日時 | 2024-10-01 17:13:04 |
| 合計ジャッジ時間 | 7,213 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
def BinarySearch(check, yes, no, i):
while abs(yes - no) != 1:
mid = (yes + no)//2
if check(mid, i):
yes = mid
else:
no = mid
return yes
N = int(input())
A = sorted(list(map(int, input().split())))
Ac = [0] * (N + 1)
for i in range(N):
Ac[i + 1] = Ac[i] + A[i]
def check(m, i):
if m == 0:
return 1
return A[-m] + A[i-m] - 2 * A[i] >= 0
ans = 0
for i in range(N):
yes = BinarySearch(check, 0, min(i, N - i) + 1, i)
ans = max(ans, Ac[-1] - Ac[-1 - yes] + Ac[i + 1] - Ac[i - yes] - (2 * yes + 1) * A[i])
print(ans)
rlangevin