@x=[] a=[] @t=[] n,k = gets.chomp.split(" ").map(&:to_i) @x+=gets.chomp.split(" ").map(&:to_i) a+=gets.chomp.split(" ").map(&:to_i) @hash = Hash[*([@x,a].transpose.flatten)] @c=0 p=@x[k-1] b=a[k-1] def f(p,w) b = @hash[p] zzz = p+w*b @x.each do |elm| if w == -1 if elm >= zzz and p > elm if @t.any? {|w| w == elm } return else @t.push(elm) end f(elm,1) f(elm,-1) end else if zzz >= elm and elm > p if @t.any? {|w| w == elm } return else @t.push(elm) end f(elm,1) f(elm,-1) end end end @c+=1 end f(p,1) f(p,-1) p @t.length