N,K=map(int,input().split()) W=[int(input()) for i in range(N)] LEN=10**6+10 BIT=[0]*(LEN+1) # 1-indexedなtree. 配列BITの長さはLEN+1にしていることに注意。 def update(v,w): # index vにwを加える while v<=LEN: BIT[v]+=w v+=(v&(-v)) # v&(-v)で、最も下の立っているビット. 自分を含む大きなノードへ. たとえばv=3→v=4 def getvalue(v): # [1,v]の区間の和を求める ANS=0 while v!=0: ANS+=BIT[v] v-=(v&(-v)) # 自分より小さい自分の和を構成するノードへ. たとえばv=14→v=12へ return ANS S=0 for w in W: if w>0: x=getvalue(w-1) if S-x>=K: True else: S+=1 update(w,1) else: w=-w if getvalue(w)>getvalue(w-1): update(w,-1) S-=1 print(S)