@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< zzz if @x[i] >=zzz and zzz1 >= @x[i] if aaa(@x[i])== true if i == xxx-1 update = false else next end else p = @x[i] 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 else p = @x[i] end elsif i == xxx-1 update = false end end end end pp=@x[k-1] #@t.compact! @y = @x.reverse update = true while(update) c = @hash[pp] zzz = pp+c zzz1 = pp+(-1*c) yyy = @y.length for i in 0...yyy do if zzz1 > zzz if @y[i] >=zzz and zzz1 >= @y[i] if aaa(@y[i])== true if i== yyy-1 update = false else next end else pp = @y[i] end elsif i == yyy-1 update = false end else if zzz >= @y[i].to_i and @y[i].to_i >= zzz1 if aaa(@y[i])== true if i== yyy-1 update = false else next end else pp = @y[i] end elsif i == yyy-1 update = false end end end end if @t==nil p "1" else p @t.length end