def read_data(): N = int(input()) # 町の数 C = int(input()) # 手持ちのお金 V = int(input()) # 道の数 S = list(map(int, input().split())) # 道の始点 T = list(map(int, input().split())) # 道の終点 Y = list(map(int, input().split())) # 道のコスト(料金) M = list(map(int, input().split())) # 道のコスト(時間) roads = [[] for i in range(N)] for s, t, y, m in zip(S, T, Y, M): roads[s-1].append((t-1, y, m)) return N, C, V, roads def solve(N, C, V, roads): ''' dp[n][c]: 町 n に所持金額 c 円でたどりつくときの、最短所要時間 dp[n][c] の状態から、cost, time でmに行けるとすると、 dp[m][c-cost] = min(dp[m][c-cost], dp[n][c] + time) で更新していけばよい。 ''' if N == 1: return 0 if C == 0: return -1 dp = [[float('inf')] * (C + 1) for c in range(N)] dp[0][C] = 0 for pos in range(N): dp_pos = dp[pos] for next_pos, cost, time in roads[pos]: dp_next = dp[next_pos] for c in range(C, 0, -1): new_c = c - cost if new_c < 0: break new_time = dp_pos[c] + time if new_time < dp_next[new_c]: dp_next[new_c] = new_time min_time = min(dp[N-1]) if min_time == float('inf'): return -1 else: return min_time if __name__ == '__main__': N, C, V, roads = read_data() print(solve(N, C, V, roads))