#include #include #include #include #include #include #include #include #include #include #include #define repd(i,a,b) for (int (i)=(a);(i)<(b);(i)++) #define rep(i,n) repd((i),0,(n)) #define inf 1000000000 typedef long long ll; using namespace std; int inputValue(){ int a; cin >> a; return a; }; template void output(T a, int precision) { if(precision > 0){ cout << setprecision(precision) << a << "\n"; } else{ cout << a << "\n"; } } int main() { // source code int N, C, V; cin >> N >> C >> V; vector S, T, Y, M; rep(i, V) S.push_back(inputValue()); rep(i, V) T.push_back(inputValue()); rep(i, V) Y.push_back(inputValue()); rep(i, V) M.push_back(inputValue()); vector>>> edge(N); rep(i, V){ edge[S[i] - 1].push_back(make_pair(T[i] - 1, make_pair(Y[i], M[i]))); } vector> dp(N, vector(C + 1, inf)); dp[0][C] = 0; rep(i, N){ rep(j, C + 1){ if (dp[i][j] == inf) continue; for (auto &k : edge[i]) { if (j - k.second.second >= 0) { dp[k.first][j - k.second.first] = min(dp[k.first][j - k.second.first], dp[i][j] + k.second.second); } } } } int ret = inf; rep(i, C + 1){ ret = min(ret, dp[N - 1][i]); } if(ret == inf) output(-1, 0); else output(ret, 0); return 0; }