結果
| 問題 |
No.972 選び方のスコア
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 18:00:43 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,039 bytes |
| コンパイル時間 | 282 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 112,512 KB |
| 最終ジャッジ日時 | 2025-03-31 18:01:48 |
| 合計ジャッジ時間 | 6,000 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 7 |
ソースコード
n = int(input())
a = list(map(int, input().split()))
a.sort()
prefix_sum_left = [0] * (n + 1)
for i in range(n):
prefix_sum_left[i+1] = prefix_sum_left[i] + a[i]
back_sum = [0] * (n + 1)
for i in range(n-1, -1, -1):
back_sum[i] = back_sum[i+1] + a[i]
max_total = -float('inf')
for i in range(n):
current = a[i]
s_left = i # Number of elements on the left that can be chosen
s_right = n - 1 - i # Elements on the right
max_s = min(s_left, s_right)
if max_s == 0:
sum_left = 0
sum_right = 0
else:
# sum_left is sum of max_s elements in the left part (i-1, i-2, ..., i-max_s)
start_left = i - max_s
sum_left = prefix_sum_left[i] - prefix_sum_left[start_left]
# sum_right is sum of max_s elements in the right part (largest max_s elements)
start_right = n - max_s
sum_right = back_sum[start_right] - back_sum[n]
total = sum_left + sum_right - 2 * max_s * current
max_total = max(max_total, total)
print(max_total)
lam6er