結果
| 問題 |
No.2028 Even Choice
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-06 07:39:07 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 204 ms / 2,000 ms |
| コード長 | 414 bytes |
| コンパイル時間 | 158 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 112,088 KB |
| 最終ジャッジ日時 | 2024-09-16 04:16:43 |
| 合計ジャッジ時間 | 4,376 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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)