結果
| 問題 |
No.2028 Even Choice
|
| コンテスト | |
| ユーザー |
Eguy
|
| 提出日時 | 2022-08-05 21:41:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 248 ms / 2,000 ms |
| コード長 | 751 bytes |
| コンパイル時間 | 1,914 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 114,192 KB |
| 最終ジャッジ日時 | 2024-09-15 18:01:25 |
| 合計ジャッジ時間 | 5,562 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
import sys, math
sys.setrecursionlimit(1000000)
INF = 1 << 100
#mod = 1000000007
mod = 998244353
input = lambda: sys.stdin.readline().rstrip()
li = lambda: list(map(int, input().split()))
from heapq import *
N, K = li()
A = li()
if K == 1:
ans = -INF
for i in range(1, N, 2):
ans = max(ans, A[i])
print(ans)
exit()
hq = []
su = 0
acc = [-INF] * N
for i in range(N)[::-1]:
a = A[i]
if len(hq) == K-1:
x = heappop(hq)
if x > a:
heappush(hq, x)
else:
heappush(hq, a)
su += a - x
else:
su += a
heappush(hq, a)
if len(hq) == K-1:
acc[i] = su
ans = -INF
for i in range(1, N-1, 2):
ans = max(ans, A[i] + acc[i+1])
print(ans)
Eguy