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