#include using namespace std; int main(){ cin.tie(nullptr)->sync_with_stdio(false); int N, C, V; cin >> N >> C >> V; vector S(V), T(V), Y(V), M(V); for(auto& x: S) cin >> x, --x; for(auto& x: T) cin >> x, --x; for(auto& x: Y) cin >> x; for(auto& x: M) cin >> x; vector>> edge(N); for(int i = 0; i < V; ++i){ edge[S[i]].emplace_back(T[i], Y[i], M[i]); } const int inf = 1e9; vector dp(N, vector(C + 1, inf)); dp.at(0).at(C) = 0; for(int i = 0; i < N; ++i){ for(int k = C; k >= 0; --k){ if(dp.at(i).at(k) == inf) continue; for(const auto& [to, cost, time]: edge[i]){ if(k < cost) continue; dp.at(to).at(k - cost) = min(dp.at(to).at(k - cost), dp.at(i).at(k) + time); } } } int minTime = *min_element(dp.at(N - 1).begin(), dp.at(N - 1).end()); if(minTime == inf) minTime = -1; cout << minTime << endl; return 0; }