#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; using vb = vector; using vvb = vector; using vd = vector; using vs = vector; using pii = pair; using pll = pair; using pdd = pair; using vpii = vector; using vpll = vector; using vpdd = vector; const int inf = (1 << 30) - 1; const ll INF = 1LL << 60; const int MOD = 1000000007; //const int MOD = 998244353; struct Edge { int to; int cost; int time; }; using Graph = vector>; int main() { int n, c, v; cin >> n >> c >> v; vi s(v), t(v), y(v), m(v); for (int i = 0; i < v; i++) cin >> s[i]; for (int i = 0; i < v; i++) cin >> t[i]; for (int i = 0; i < v; i++) cin >> y[i]; for (int i = 0; i < v; i++) cin >> m[i]; Graph g(n + 1); for (int i = 0; i < v; i++) { g[s[i]].push_back({ t[i],y[i],m[i] }); } vvi dp(n + 1, vi(c + 1, inf)); dp[1][0] = 0; for (int i = 1; i < n; i++) { for (int j = 0; j <= c; j++) { if (dp[i][j] == inf) continue; for (auto& u : g[i]) { if (j + u.cost > c) continue; dp[u.to][j + u.cost] = min(dp[u.to][j + u.cost], dp[i][j] + u.time); } } } int ans = inf; for (int i = 0; i <= c; i++) { ans = min(ans, dp[n][i]); } if (ans == inf) cout << -1 << endl; else cout << ans << endl; return 0; }