#include using namespace std; using ll = long long; using PII = std::pair; using PLL = std::pair; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { #ifdef DEBUG cout << "DEBUG MODE" << endl; ifstream in("input.txt"); //for debug cin.rdbuf(in.rdbuf()); //for debug #endif const int inf = 1e9; int n, c, v, x, si, ti, yi, mi, ans; cin >> n >> c >> v; int s[v], t[v], y[v], m[v]; vector> roads; rep(i, v) { cin >> s[i]; } rep(i, v) { cin >> t[i]; } rep(i, v) { cin >> y[i]; } rep(i, v) { cin >> m[i]; } rep(i, v) { roads.push_back(make_tuple(s[i] - 1, t[i] - 1, y[i], m[i])); } sort(roads.begin(), roads.end()); // for (auto z : roads) // cout << get<0>(z) << " " << get<1>(z) << " " << get<2>(z) << " " << get<3>(z) << "\n"; int dp[n][c + 1]; rep(i, n) rep(j, c + 1) dp[i][j] = inf; dp[0][0] = 0; for (auto z : roads) { si = get<0>(z), ti = get<1>(z), yi = get<2>(z), mi = get<3>(z); rep(i, c + 1) { if (i + yi <= c) dp[ti][i + yi] = min(dp[ti][i + yi], dp[si][i] + mi); } } // rep(i, n){ // rep(j, c+1) // { // cout << dp[i][j] << " "; // } // cout << "\n"; // } ans = *min_element(dp[n - 1], dp[n - 1] + c + 1); cout << ((ans == inf) ? -1 : ans) << endl; return 0; }