#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n, c, v; cin >> n >> c >> v; vector Graph(n, vector>()); { vector s(v), t(v), y(v), m(v); rep(i, v) cin >> s[i]; rep(i, v) cin >> t[i]; rep(i, v) cin >> y[i]; rep(i, v) cin >> m[i]; rep(i, v) { Graph[--s[i]].push_back({ --t[i], y[i], m[i] }); } } constexpr ll INF = 1e18; vector dist(c + 1, vector(n, INF)); dist[0][0] = 0; priority_queue, vector>, greater<>> pq; pq.push({ 0, 0, 0 }); while (!pq.empty()) { auto [d, co, v] = pq.top(); pq.pop(); for (auto [nv, y, m] : Graph[v]) { if (co + y <= c && dist[co + y][nv] > dist[co][v] + m) { dist[co + y][nv] = dist[co][v] + m; pq.push({ dist[co + y][nv], co + y, nv }); } } } ll ans = INF; rep(i, c + 1) ans = min(ans, dist[i][n - 1]); cout << (ans == INF ? -1 : ans) << endl; return 0; }