(N,X),A=$<.map{_1.split.map &:to_i} t=0 p A.map{X<0?-_1:_1}.sort.sum{-[X=X.abs,[t,_1-30].max].min+t=[X,[0,_1].max].min}