#define _CRT_SECURE_NO_WARNINGS #include #include #include #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) < (n) ; ++(i)) #define REPA(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i)) #if defined(_MSC_VER)||__cplusplus > 199711L #define AUTO(r,v) auto r = (v) #else #define AUTO(r,v) typeof(v) r = (v) #endif #define ALL(c) (c).begin() , (c).end() #define EACH(it,c) for(AUTO(it,(c).begin());it != (c).end();++it) #define LL long long #define int LL #define INF 999999999999 #define DEV 1000000007 #define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0); using namespace std; int dmin[55][350]; int N, V , C; int S[55]; int T[55]; int Y[55][55]; int M[55][55]; signed main() { QUICK_CIN; //ifstream cin("debug.txt"); //ofstream cout("result.txt"); cin >> N >> C >> V; REP(i, 54) { REP(j, 350) { dmin[i+1][j] = INF; } } REP(i, V) cin >> S[i]; REP(i, V){ cin >> T[i]; } REP(i, 55)REP(j,55){ Y[i][j] = M[i][j] = INF; } //Y is cost REP(i, V){ cin >> Y[S[i]-1][T[i]-1]; } //M is time REP(i, V){ cin >> M[S[i]-1][T[i]-1]; } REP(i, N-1) { REP(j, 350) { REP(k, 55) { if (Y[i][k] != INF && Y[i][k] + j < 350) { dmin[k][j + Y[i][k]] = min(dmin[k][j + Y[i][k]], dmin[i][j] + M[i][k]); } } } } if (dmin[N - 1][C] == INF) { cout << -1 << endl; return 0; } cout << dmin[N - 1][C] << endl; return 0; }