結果
| 問題 |
No.1117 数列分割
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-04 17:10:28 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 973 bytes |
| コンパイル時間 | 209 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 34,340 KB |
| 最終ジャッジ日時 | 2024-11-30 03:18:45 |
| 合計ジャッジ時間 | 72,081 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 TLE * 14 |
ソースコード
from collections import deque
n,k,m=map(int,input().split())
a=list(map(int,input().split()))+[0]
for i in range(n-1,-1,-1):
a[i]+=a[i+1]
plus=[deque([]) for j in range(k)]
plus[0].append((-1,a[0]))
minus=[deque([]) for j in range(k)]
minus[0].append((-1,-a[0]))
for i in range(n):
for j in range(k-1,-1,-1):
res=0
while plus[j] and plus[j][0][0]<i-m:
plus[j].popleft()
while minus[j] and minus[j][0][0]<i-m:
minus[j].popleft()
if plus[j]:
res=max(res,plus[j][0][1]-a[i+1])
if minus[j]:
res=max(res,minus[j][0][1]+a[i+1])
if j+1<k:
while plus[j+1] and plus[j+1][-1][1]<=res+a[i+1]:
plus[j+1].pop()
while minus[j+1] and minus[j+1][-1][1]<=res-a[i+1]:
minus[j+1].pop()
plus[j+1].append((i,res+a[i+1]))
minus[j+1].append((i,res-a[i+1]))
if i==n-1 and j==k-1:
print(res)