結果
問題 |
No.2028 Even Choice
|
ユーザー |
![]() |
提出日時 | 2022-08-06 12:27:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 224 ms / 2,000 ms |
コード長 | 464 bytes |
コンパイル時間 | 163 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 112,096 KB |
最終ジャッジ日時 | 2024-09-16 08:38:32 |
合計ジャッジ時間 | 5,408 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
from heapq import heapify, heappop, heappush N, K = map(int, input().split()) A = list(map(int, input().split())) hp = [] heapify(hp) s = 0 ans = 0 for i in range(N - 1, -1, -1): if (N - 1 - i) < K -1: heappush(hp, A[i]) s += A[i] else: if i & 1: while len(hp) != K - 1: a = heappop(hp) s -= a ans = max(ans, s + A[i]) heappush(hp, A[i]) s += A[i] print(ans)