#include #define int long long #define REP(i, b) for(int i = 0; i < (b); i++) #define REPS(i, b) for(int i = 1; i <= (b); i++) #define ALL(v) (v).begin(), (v).end() using namespace std; using pi = pair; using vi = vector; using vs = vector; using vb = vector; using vpi = vector; using vvi = vector; using vvb = vector; const int INF = 1e10; const int MOD = 1e9+7; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); typedef struct { int to, cost, time; } Edge; int N, C, V; cin >> N >> C >> V; vi 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]; vector> E(N); REP(i, V) { E[S[i]-1].push_back(Edge{T[i]-1, Y[i], M[i]}); } vvi dp(N, vi(500000, INF)); dp[0][0] = 0; REP(i, N-1) { REP(j, E[i].size()) { REP(k, 500000) { if(dp[i][k] != INF) chmin(dp[E[i][j].to][k+E[i][j].cost], dp[i][k]+E[i][j].time); } } } int ans = INF; REP(i, C+1) chmin(ans, dp[N-1][i]); if(ans == INF) cout << -1 << endl; else cout << ans << endl; }