#include using namespace std; int main() { int N, C, V, S[1510], T[1510], Y[1510], M[1510]; cin >> N >> C >> 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]; struct road { int nxt_town, nxt_money, time; }; vector G[52][302]; for (int i = 0; i < V; ++i) { for (int j = 0; j <= C; ++j) { if (j + Y[i] <= C) { G[S[i]][j + Y[i]].push_back({T[i], j, M[i]}); } } } int dp[52][302]; memset(dp, 1000000, sizeof(dp)); priority_queue>, vector>>, greater>>> que; que.push({0, {1, C}}); while (!que.empty()) { auto q = que.top(); que.pop(); int time = q.first; auto now = q.second; if (dp[now.first][now.second] < time) continue; dp[now.first][now.second] = time; for (auto& nxt : G[now.first][now.second]) { que.push({time + nxt.time, {nxt.nxt_town, nxt.nxt_money}}); } } int ans = 1000000; for (int i = 0; i <= C; i++) { ans = min(ans, dp[N][i]); } if (ans == 1000000) ans = -1; cout << ans << endl; }