#include "bits/stdc++.h" using namespace std; #define MAX 9999999 int main() { int n,c,v; vector s,t,y,m; cin>>n>>c>>v; for (int i = 0; i < v; ++i) { int a; cin>>a; a--; s.push_back(a); } for (int i = 0; i < v; ++i) { int a; cin>>a; a--; t.push_back(a); } for (int i = 0; i < v; ++i) { int a; cin>>a; y.push_back(a); } for (int i = 0; i < v; ++i) { int a; cin>>a; m.push_back(a); } vector > > lib(n); for (int j = 0; j < v; ++j) { lib[s[j]].push_back(make_tuple(t[j], y[j], m[j])); } vector< vector > dp(n, vector(c+1, MAX)); dp[0][c] = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < c + 1; ++j) { if (dp[i][j] == MAX) continue; for (auto e: lib[i]) { int dest = get<0>(e); int cost = j - get<1>(e); int time = dp[i][j] + get<2>(e); if (time < 0) continue; dp[dest][cost] = min(time, dp[dest][cost]); } } } int ans = MAX; for (int i = 0; i < c + 1; ++i) { ans = min(ans, dp[n-1][i]); } if (ans == MAX) cout<<-1<