After 40 minutes, Ralph has already painted (40/60)/12=1/18 of the fence
Lisa's speed is 1/15 fence/hour, Ralph's speed is 1/12 fence/hour, hence when they help each other their combined speed is 1/15+1/12=3/20
Thus we need to solve 3/20*x=17/18 thus x=170/27 hours (approx 6 hours 15 mins)