結果
| 問題 |
No.1522 Unfairness
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 18:53:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 928 bytes |
| コンパイル時間 | 199 ms |
| コンパイル使用メモリ | 82,240 KB |
| 実行使用メモリ | 76,960 KB |
| 最終ジャッジ日時 | 2025-06-12 18:53:40 |
| 合計ジャッジ時間 | 2,941 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 22 |
ソースコード
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
for k in range(0, n//2 + 1):
if 2 * k > n:
continue
if k == 0:
ans = max(ans, 0)
continue
# Select the largest k and smallest k elements
a_part = a[:k]
b_part = sorted(a[n - k:], reverse=True)
# Merge the two sorted arrays in descending order
merged = []
i = j = 0
while i < k and j < k:
if a_part[i] >= b_part[j]:
merged.append(a_part[i])
i += 1
else:
merged.append(b_part[j])
j += 1
merged.extend(a_part[i:])
merged.extend(b_part[j:])
# Calculate O and the difference sum
diff_sum = 0
o_sum = 0
for i in range(k):
o = merged[2 * i]
e = merged[2 * i + 1]
o_sum += o
diff_sum += o - e
if diff_sum <= m:
ans = max(ans, o_sum)
print(ans)
gew1fw