#include #include #include #include #include #include #include #include using namespace std; using ll = long long; const ll INF = 1e9; const ll MOD = 1e9 + 7; vector> adj[50]; ll dp[52][302]; // dp[n][c] = 都市nにc円以下で行く最短時間 int main() { int N, C, V; cin >> N >> C >> V; vector S(V); for (int i = 0; i < V; i++) { cin >> S[i]; S[i]--; } vector T(V); for (int i = 0; i < V; i++) { cin >> T[i]; T[i]--; } vector Y(V); for (int i = 0; i < V; i++) { cin >> Y[i]; } for (int i = 0; i < V; i++) { int M; cin >> M; adj[S[i]].push_back({T[i], Y[i], M}); } for (int n = 0; n < N; n++) for (int c = 0; c <= C; c++) dp[n][c] = INF; dp[0][0] = 0; for (int n = 0; n < N; n++) { for (int c = 0; c <= C; c++) { for (int i = 0; i < adj[n].size(); i++) { int dst = adj[n][i][0]; int y = adj[n][i][1]; int t = adj[n][i][2]; if (c + y <= C) { dp[dst][c+y] = min(dp[dst][c+y], dp[n][c] + t); // cout << n << " " << dst << " " << y << " " << t << endl; } } } } ll mi = INF; for (int i = 0; i < C; i++) { mi = min(mi, dp[N-1][i]); } cout << (mi == INF ? -1 : mi) << endl; return 0; }