#include #include #include #include #define REP(i,a,b) for(int i=(a); i<(b); i++) #define p_int pair using namespace std; int main(){ // 街の数、コスト上限、道の数 int city_n, c_max, load_n; cin >> city_n >> c_max >> load_n; // 始点、終点、コスト、時間 int s[load_n], t[load_n], c[load_n], time[load_n]; REP(i, 0, load_n) cin >> s[i]; REP(i, 0, load_n) cin >> t[i]; // sから行ける場所のvectorの配列 vector st[city_n + 1]; REP(i, 0, load_n) st[s[i]].push_back(make_pair(t[i], i)); REP(i, 0, load_n) cin >> c[i]; REP(i, 0, load_n) cin >> time[i]; // 使った費用を縦軸、現在地を横軸に取ってDP int dp[c_max + 1][city_n + 1]; REP(i, 0, c_max + 1){ REP(j, 0, city_n + 1){ dp[i][j] = INT_MAX; } } dp[0][1] = 0; queue q; q.push(make_pair(0, 1)); while (!(q.empty())){ // queueの先頭の要素を取り出し、そこから行ける都市を調べる p_int front = q.front(); q.pop(); // 場所とそこまでのコスト int c_front = front.first; int s_front = front.second; vector t_goto = st[s_front]; REP(i, 0, t_goto.size()){ p_int t_goto_i = t_goto[i]; int t_next = t_goto_i.first; int iter = t_goto_i.second; int c_next = c_front + c[iter]; if (c_next <= c_max) { int time_next = dp[c_front][s_front] + time[iter]; dp[c_next][t_next] = min(dp[c_next][t_next], time_next); q.push(make_pair(c_next, t_next)); } } } // dp[i][city_n]における最小値を返す int ans = INT_MAX; REP(i, 0, c_max + 1){ ans = min(ans, dp[i][city_n]); } if (ans == INT_MAX) cout << -1 << endl; else cout << ans << endl; return 0; }