@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)] p=@x[k-1] def aaa(elm) if @t.any? {|w| w == elm } return true else @t.compact! @t< zzz if @x[i] >=zzz and zzz1 >= @x[i] if aaa(@x[i])== true if i == xxx-1 break else next end else p = @x[i] break end elsif i == xxx-1 break end else if zzz >= @x[i].to_i and @x[i].to_i >= zzz1 if aaa(@x[i])== true if i == xxx-1 break else next end else p = @x[i] break end elsif i == xxx-1 break end end end else @t.each do |elm| b = @hash[elm] zzz = elm+b zzz1 = elm+(-1*b) xxx = @x.length for i in 0...xxx do if zzz1 > zzz if @x[i] >=zzz and zzz1 >= @x[i] if aaa(@x[i])== true if i == xxx-1 update = false else next end end elsif i == xxx-1 update = false end else if zzz >= @x[i].to_i and @x[i].to_i >= zzz1 if aaa(@x[i])== true if i == xxx-1 update = false else next end end elsif i == xxx-1 update = false end end end end end end #if @t==nil # p "1" #else p @t.length #end