結果

問題 No.2139 K Consecutive Sushi
ユーザー titiatitia
提出日時 2022-12-03 00:32:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 914 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 108,436 KB
最終ジャッジ日時 2024-04-18 09:38:59
合計ジャッジ時間 7,159 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,096 KB
testcase_01 AC 33 ms
51,712 KB
testcase_02 AC 37 ms
51,968 KB
testcase_03 AC 237 ms
103,788 KB
testcase_04 AC 260 ms
104,164 KB
testcase_05 AC 275 ms
104,168 KB
testcase_06 AC 261 ms
103,880 KB
testcase_07 AC 239 ms
103,912 KB
testcase_08 AC 222 ms
104,192 KB
testcase_09 AC 233 ms
104,264 KB
testcase_10 AC 225 ms
104,164 KB
testcase_11 AC 229 ms
104,212 KB
testcase_12 AC 218 ms
104,032 KB
testcase_13 AC 36 ms
51,584 KB
testcase_14 AC 35 ms
52,096 KB
testcase_15 AC 40 ms
52,352 KB
testcase_16 AC 39 ms
51,968 KB
testcase_17 AC 41 ms
51,840 KB
testcase_18 AC 79 ms
76,416 KB
testcase_19 AC 93 ms
76,416 KB
testcase_20 AC 88 ms
76,508 KB
testcase_21 AC 45 ms
56,960 KB
testcase_22 AC 91 ms
76,544 KB
testcase_23 AC 116 ms
77,952 KB
testcase_24 AC 160 ms
85,148 KB
testcase_25 AC 219 ms
101,376 KB
testcase_26 AC 126 ms
77,952 KB
testcase_27 AC 158 ms
83,584 KB
testcase_28 AC 151 ms
83,868 KB
testcase_29 AC 122 ms
79,520 KB
testcase_30 AC 171 ms
87,512 KB
testcase_31 AC 243 ms
108,436 KB
testcase_32 AC 120 ms
80,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int,input().split())
A=list(map(int,input().split()))

seg_el=1<<((N+2).bit_length()) # Segment treeの台の要素数
SEG=[1<<62]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

def update(n,x,seg_el): # A[n]をxへ更新
    i=n+seg_el
    SEG[i]=x
    i>>=1 # 子ノードへ
    
    while i!=0:
        SEG[i]=min(SEG[i*2],SEG[i*2+1])
        i>>=1

def getvalues(l,r): # 区間[l,r)に関するminを調べる
    L=l+seg_el
    R=r+seg_el
    ANS=1<<62

    while L<R:
        if L & 1:
            ANS=min(ANS , SEG[L])
            L+=1

        if R & 1:
            R-=1
            ANS=min(ANS , SEG[R])
        L>>=1
        R>>=1

    return ANS

update(0,0,seg_el)

for i in range(N):
    a=A[i]
    u=getvalues(max(0,i+1-K),i+1)

    update(i+1,u+a,seg_el)

ANS=[getvalues(i,i+1) for i in range(N+2)]

AS=getvalues(N+1-K,N+1)

print(sum(A)-AS)
    
0