package main import ( "fmt" ) func min(x, y int) int { if y < x { return y } return x } type e struct { v int c int t int } func main() { Inf := 1 << 28 var N, C, V int fmt.Scan(&N, &C, &V) var S, T, Y, M [1510]int for i := 0; i < V; i++ { fmt.Scan(&S[i]) } for i := 0; i < V; i++ { fmt.Scan(&T[i]) } for i := 0; i < V; i++ { fmt.Scan(&Y[i]) } for i := 0; i < V; i++ { fmt.Scan(&M[i]) } E := make([][]e, N) for i := 0; i < V; i++ { from, to, cost, time := S[i], T[i], Y[i], M[i] from-- to-- E[from] = append(E[from], e{v: to, c: cost, t: time}) } dp := make([][]int, N) for i := 0; i < N; i++ { dp[i] = make([]int, C+1) for j := 0; j <= C; j++ { dp[i][j] = Inf } } dp[0][C] = 0 for i := 0; i < N; i++ { for c0 := C; c0 > 0; c0-- { if dp[i][c0] == Inf { continue } for _, e := range E[i] { if c0-e.c < 0 { continue } dp[e.v][c0-e.c] = min(dp[e.v][c0-e.c], dp[i][c0]+e.t) } } } res := Inf for i := 0; i < C; i++ { res = min(res, dp[N-1][i]) } if res == Inf { res = -1 } fmt.Println(res) }