結果

問題 No.2139 K Consecutive Sushi
ユーザー とりゐとりゐ
提出日時 2022-12-03 01:10:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 109,184 KB
最終ジャッジ日時 2024-04-18 10:25:36
合計ジャッジ時間 5,907 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,480 KB
testcase_01 AC 40 ms
52,096 KB
testcase_02 AC 37 ms
52,736 KB
testcase_03 AC 237 ms
105,088 KB
testcase_04 AC 256 ms
104,952 KB
testcase_05 AC 213 ms
104,948 KB
testcase_06 AC 197 ms
105,212 KB
testcase_07 AC 209 ms
105,460 KB
testcase_08 AC 245 ms
105,696 KB
testcase_09 AC 234 ms
105,724 KB
testcase_10 AC 243 ms
106,208 KB
testcase_11 AC 224 ms
105,720 KB
testcase_12 AC 224 ms
105,728 KB
testcase_13 AC 40 ms
52,224 KB
testcase_14 AC 37 ms
52,224 KB
testcase_15 AC 35 ms
52,608 KB
testcase_16 AC 39 ms
52,352 KB
testcase_17 AC 40 ms
52,540 KB
testcase_18 AC 78 ms
76,416 KB
testcase_19 AC 75 ms
74,880 KB
testcase_20 AC 68 ms
71,936 KB
testcase_21 AC 41 ms
57,600 KB
testcase_22 AC 86 ms
76,416 KB
testcase_23 AC 104 ms
78,144 KB
testcase_24 AC 133 ms
85,724 KB
testcase_25 AC 200 ms
102,736 KB
testcase_26 AC 102 ms
77,952 KB
testcase_27 AC 139 ms
84,408 KB
testcase_28 AC 131 ms
84,608 KB
testcase_29 AC 115 ms
79,488 KB
testcase_30 AC 135 ms
88,696 KB
testcase_31 AC 221 ms
109,184 KB
testcase_32 AC 101 ms
80,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class segtree():
  def __init__(self,init,func,ide):
    self.n=len(init)
    self.func=func
    self.ide=ide
    self.size=1<<(self.n-1).bit_length()
    self.tree=[self.ide for i in range(2*self.size)]
    for i in range(self.n):
      self.tree[self.size+i]=init[i]
    for i in range(self.size-1,0,-1):
      self.tree[i]=self.func(self.tree[2*i], self.tree[2*i|1])
  
  def update(self,k,x):
    k+=self.size
    self.tree[k]=x
    k>>=1
    while k:
      self.tree[k]=self.func(self.tree[2*k],self.tree[k*2|1])
      k>>=1
  
  def get(self,i):
    return self.tree[i+self.size]
  
  def query(self,l,r):
    l+=self.size
    r+=self.size
    l_res=self.ide
    r_res=self.ide
    while l<r:
      if l&1:
        l_res=self.func(l_res,self.tree[l])
        l+=1
      if r&1:
        r-=1
        r_res=self.func(self.tree[r],r_res)
      l>>=1
      r>>=1
    return self.func(l_res,r_res)
  
  def debug(self,s=10):
    print([self.get(i) for i in range(min(self.n,s))])

n,k=map(int,input().split())
a=list(map(int,input().split()))
seg=segtree([0]*n,min,10**18)
for i in range(n):
  if i<k-1:
    seg.update(i,a[i])
    continue
  mn=seg.query(i-k,i)
  seg.update(i,mn+a[i])

print(sum(a)-seg.query(n-k,n))
0