結果
問題 |
No.2028 Even Choice
|
ユーザー |
|
提出日時 | 2025-04-26 00:07:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 332 ms / 2,000 ms |
コード長 | 772 bytes |
コンパイル時間 | 411 ms |
コンパイル使用メモリ | 82,180 KB |
実行使用メモリ | 112,880 KB |
最終ジャッジ日時 | 2025-04-26 00:07:28 |
合計ジャッジ時間 | 7,639 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
## https://yukicoder.me/problems/no/2028 import heapq def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) answer = 0 queue = [] ans = 0 for i in reversed(range(1, N, 2)): if i + 1 < N: a = A[i + 1] heapq.heappush(queue, a) ans += a if len(queue) > K - 1: b = heapq.heappop(queue) ans -= b if len(queue) >= K - 1: ans2 = ans + A[i] answer = max(answer, ans2) a = A[i] heapq.heappush(queue, a) ans += a if len(queue) > K - 1: b = heapq.heappop(queue) ans -= b print(answer) if __name__ == "__main__": main()