#include #include #include #include #include #define rep(i,a) for(int i=0;i<(a);++i) const int INF = std::numeric_limits::max(); template void chmin( T &a, T b ) { a = std::min( a, b ); return; } struct edge { int to, cost, tim; edge( int to, int cost, int tim ) : to(to), cost(cost), tim(tim) {} }; int N, C, V; std::vector G[50]; int S[1500], T[1500], Y[1500], M[1500]; int main() { scanf( "%d%d%d", &N, &C, &V ); rep( i, V ) scanf( "%d", S+i ); rep( i, V ) scanf( "%d", T+i ); rep( i, V ) scanf( "%d", Y+i ); rep( i, V ) scanf( "%d", M+i ); rep( i, V ) G[S[i]-1].push_back( edge( T[i]-1, Y[i], M[i] ) ); std::vector > dp( N, std::vector( C+1, INF ) ); rep( j, C+1 ) dp[0][j] = 0; rep( i, N ) rep( k, C+1 ) if( dp[i][k] != INF ) rep( j, G[i].size() ) if( k+G[i][j].cost <= C ) chmin( dp[G[i][j].to][k+G[i][j].cost], dp[i][k]+G[i][j].tim ); printf( "%d\n", dp[N-1][C]==INF?-1:dp[N-1][C] ); return 0; }