#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) #if defined(_MSC_VER) || __cplusplus > 199711L #define aut(r,v) auto r = (v) #else #define aut(r,v) __typeof(v) r = (v) #endif #define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it) #define all(o) (o).begin(), (o).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset(m,v,sizeof(m)) #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL using namespace std; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template inline void amin(T &x, U y) { if(y < x) x = y; } template inline void amax(T &x, U y) { if(x < y) x = y; } int main() { int N, C, V; while(cin >> N >> C >> V) { vi S(V), T(V), Y(V), M(V); rep(i, V) cin >> S[i], -- S[i]; rep(i, V) cin >> T[i], -- T[i]; rep(i, V) cin >> Y[i]; rep(i, V) cin >> M[i]; vector dp(C+1, vi(N, INF)); rer(c, 0, C) dp[c][0] = 0; rep(c, C) { rep(i, V) { int s = S[i], t = T[i], y = Y[i], m = M[i]; if(c+y <= C) amin(dp[c+y][t], dp[c][s] + m); } } int ans = dp[C][N-1]; if(ans == INF) puts("-1"); else printf("%d\n", ans); } return 0; }