結果
| 問題 | No.2028 Even Choice |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-06 07:39:07 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 154 ms / 2,000 ms |
| コード長 | 414 bytes |
| 記録 | |
| コンパイル時間 | 189 ms |
| コンパイル使用メモリ | 84,864 KB |
| 実行使用メモリ | 123,264 KB |
| 最終ジャッジ日時 | 2026-04-05 08:52:43 |
| 合計ジャッジ時間 | 3,304 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
import sys
input = sys.stdin.readline
from heapq import *
N, K = map(int, input().split())
A = list(map(int, input().split()))
pq = []
s = 0
for i in range(N-1, N-K, -1):
heappush(pq, A[i])
s += A[i]
ans = 0
for i in range(N-K, -1, -1):
if i%2==1:
ans = max(ans, A[i]+s)
if len(pq)>0 and pq[0]<A[i]:
s -= heappop(pq)
heappush(pq, A[i])
s += A[i]
print(ans)