n=gets.to_i c=gets.to_i v=gets.to_i s=gets.split.map{|e| e.to_i} t=gets.split.map{|e| e.to_i} y=gets.split.map{|e| e.to_i} m=gets.split.map{|e| e.to_i} g=51.times.map{[]} s.size.times{|i| g[s[i]]<<[t[i],y[i],m[i]] } hs={} hs[[1,0]]=0 dp={} dp[[1,0]]=0 inf=10**9 ans=inf while dp.empty? == false dp2={} dp.each{|e2,v| if e2[0]==n ans=[ans,v].min end cost=e2[1] g[e2[0]].each{|e3| nextCity=e3[0] addCost=e3[1] addTime=e3[2] cost2=cost+addCost time2=v+addTime if cost2>c next end e4=[nextCity,cost2] if hs.key?(e4)==false || hs[e4]>time2 hs[e4]=time2 dp2[e4]=time2 end } } dp=dp2 end if ans==inf puts -1 else puts ans end