結果
問題 |
No.1117 数列分割
|
ユーザー |
|
提出日時 | 2020-07-04 17:09:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,963 ms / 3,000 ms |
コード長 | 973 bytes |
コンパイル時間 | 198 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 161,272 KB |
最終ジャッジ日時 | 2024-11-30 03:19:08 |
合計ジャッジ時間 | 17,324 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
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)