#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int memo[50][301]; int ygraph[50][50]; int mgraph[50][50]; int n, c; int ans; #define INF 1000000000 int rec(int i, int j, int k) { if (j < 0) return INF; if (i == n-1) { ans = min(k, ans); return ans; } if (memo[i][j] != INF) { if (memo[i][j] > k) { memo[i][j] = k; }else { return memo[i][j]; } } // cout << i << " " << j << " " << k << endl; int ret = INF; for (int p = i+1; p < n; p++) { if (!ygraph[i][p]) continue; ret = min(ret, rec(p, j-ygraph[i][p], k+mgraph[i][p])); } return memo[i][j]=ret; } int main() { for (int i = 0; i < 50; i++) { for (int j = 0; j <= 301; j++) { memo[i][j] = INF; } } cin >> n; cin >> c; int v; cin >> v; int s[v], t[v], y[v], m[v]; memset(ygraph, 0, sizeof(ygraph)); memset(mgraph, 0, sizeof(mgraph)); for (int i = 0; i < v; i++) cin >> s[i]; for (int i = 0; i < v; i++) cin >> t[i]; for (int i = 0; i < v; i++) cin >> y[i]; for (int i = 0; i < v; i++) cin >> m[i]; for (int i = 0; i < v; i++) { ygraph[s[i]-1][t[i]-1] = y[i]; mgraph[s[i]-1][t[i]-1] = m[i]; } ans = INF; if (rec(0, c, 0) != INF) { cout << ans << endl; }else { cout << -1 << endl; } }