結果
| 問題 |
No.2028 Even Choice
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-19 08:46:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 350 ms / 2,000 ms |
| コード長 | 547 bytes |
| コンパイル時間 | 309 ms |
| コンパイル使用メモリ | 82,172 KB |
| 実行使用メモリ | 112,160 KB |
| 最終ジャッジ日時 | 2024-11-19 08:46:41 |
| 合計ジャッジ時間 | 6,940 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
import heapq
N,K = map(int,input().split())
A = list(map(int,input().split()))
heap = []
ans = 0
for i in range(N-1,N-K,-1):
ans += A[i]
heapq.heappush(heap,A[i])
cur = N-K
if cur%2==0:
ans += A[cur]
heapq.heappush(heap,A[cur])
ans -= heapq.heappop(heap)
cur -= 1
ans += A[cur]
cnt = ans
while cur>=3:
heapq.heappush(heap,A[cur])
cnt -= heapq.heappop(heap)
cur -= 1
cnt += A[cur]
heapq.heappush(heap,A[cur])
cnt -= heapq.heappop(heap)
cur -= 1
cnt += A[cur]
ans = max(cnt,ans)
print(ans)