#include using namespace std; template struct Edge { int from, to; T cost; int idx; Edge() {} Edge(int to_) : to(to_) {} Edge(int to_, T cost_) : to(to_), cost(cost_) {} Edge(int from_, int to_, int idx_) : from(from_), to(to_), idx(idx_) {} Edge(int from_, int to_, T cost_, int idx_) : from(from_), to(to_), cost(cost_), idx(idx_) {} }; template using Graph = vector>>; using graph = Graph; using edge = Edge; #define add emplace_back int main() { int n, c, v; cin >> n >> c >> v; vector s(v), t(v), y(v), m(v); for (int i = 0; i < v; i++) { cin >> s[i]; s[i]--; } for (int i = 0; i < v; i++) { cin >> t[i]; 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); for (int i = 0; i < v; i++) { pair p = {y[i], m[i]}; g[s[i]].add(t[i], p); } vector> dp(n, vector(c + 1, 1e9)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= c; j++) { for (auto e : g[i]) { int ni = e.to, money = e.cost.first, jikan = e.cost.second; int nj = j + money; if (nj <= c) { dp[ni][nj] = min(dp[ni][nj], dp[i][j] + jikan); } } } } int ans = 1e9; for (int j = 0; j <= c; j++) { ans = min(ans, dp[n - 1][j]); } cout << (ans != 1e9 ? ans : -1) << endl; }