#include #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define REPR(i, n) for(int i = (int)(n); i >= 0; i--) #define FOR(i, s, n) for (int i = (s); i < (int)(n); i++) #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; ll N, K, W, H, M, C, V; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; vector cx, cy, c; ll MM = 1e12; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main(){ cin >> N >> C >> V; vector c(V), t(V), y(V), m(V); REP(i, V){cin >> c[i]; c[i]--;} REP(i, V){cin >> t[i]; t[i]--;} REP(i, V) cin >> y[i]; REP(i, V) cin >> m[i]; vector> dp(N, vector (C + 1, MM)); vector>> edge(N); REP(i,V){ tuple tp = make_tuple(t[i], y[i], m[i]) ; edge[c[i]].push_back(tp); } dp[0][C] = 0; for(int i = 0; i < N; ++i){ for(int j = 0; j <= C; ++j){ if(dp[i][j] >= MM) continue; for(auto e: edge[i]){ int node = get<0>(e); ll leftover = j - get<1>(e); ll tim = get<2>(e); if(leftover < 0) continue; dp[node][leftover] = min(dp[node][leftover], dp[i][j] + tim ); } } } ll ans = MM; for(int i = 0; i < C+1; ++i){ ans = min(ans, dp[N-1][i]); } if(ans == MM) cout << -1; else cout << ans; return 0; }