結果
| 問題 |
No.2028 Even Choice
|
| コンテスト | |
| ユーザー |
Eguy
|
| 提出日時 | 2022-08-05 21:38:05 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 685 bytes |
| コンパイル時間 | 442 ms |
| コンパイル使用メモリ | 82,220 KB |
| 実行使用メモリ | 114,260 KB |
| 最終ジャッジ日時 | 2024-09-15 17:57:01 |
| 合計ジャッジ時間 | 5,362 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 3 |
ソースコード
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:
print(max(A[1:]))
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