結果
問題 |
No.2028 Even Choice
|
ユーザー |
![]() |
提出日時 | 2025-06-12 21:39:02 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,039 bytes |
コンパイル時間 | 449 ms |
コンパイル使用メモリ | 82,208 KB |
実行使用メモリ | 289,536 KB |
最終ジャッジ日時 | 2025-06-12 21:43:36 |
合計ジャッジ時間 | 6,830 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | TLE * 1 -- * 27 |
ソースコード
import heapq def main(): import sys input = sys.stdin.read data = input().split() N = int(data[0]) K = int(data[1]) A = list(map(int, data[2:2+N])) current = A.copy() heap = [] for i in range(1, N+1): if i % 2 == 0: heapq.heappush(heap, (-current[i-1], i-1)) # Using max-heap by negating sum_k = 0 for _ in range(K): if not heap: break val, idx = heapq.heappop(heap) val = -val sum_k += val # Now, update all elements after idx for j in range(idx+1, N): current[j-1] = current[j] current.pop() N -= 1 # Add new even positions new_heap = [] for i in range(1, N+1): if i % 2 == 0: pos = i-1 if pos >= len(current): continue heapq.heappush(new_heap, (-current[pos], pos)) heap = new_heap print(sum_k) if __name__ == "__main__": main()