結果
| 問題 |
No.2028 Even Choice
|
| コンテスト | |
| ユーザー |
ニックネーム
|
| 提出日時 | 2022-08-05 22:48:36 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 469 ms / 2,000 ms |
| コード長 | 506 bytes |
| コンパイル時間 | 80 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 32,736 KB |
| 最終ジャッジ日時 | 2024-09-15 20:13:20 |
| 合計ジャッジ時間 | 5,731 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
from heapq import heappop, heappush
n, k = map(int, input().split())
a = list(map(int, input().split()))
if k == 1: print(max(a[1::2])); exit()
hq = []
s = 0
ans = 0
for i in range(n-1, -1, -1):
if len(hq) < k-1:
heappush(hq, a[i])
s += a[i]
elif i%2 == 0:
m = heappop(hq)
heappush(hq, max(a[i], m))
s += max(a[i], m)-m
else:
ans = max(ans, a[i]+s)
m = heappop(hq)
heappush(hq, max(a[i], m))
s += max(a[i], m)-m
print(ans)
ニックネーム