BIT=[0]*1000001 def add x,v;(BIT[x]+=v;x+=x&-x)while BIT[x];end def sum x;s=0;(s+=BIT[x];x&=x-1)while x>0;s;end l=[] _,k,*t=$<.read.split.map &:to_i cnt=Hash.new{0} all=0 t.map{|w| if w>0 if all-sum(w-1)0 cnt[-w]-=1 all-=1 add(-w,-1) end end } p all