#define print(x) printf("%d\n",x) #include #define REP(i,n) for(int i=0; i<(int)(n); i++) #include #include inline int getInt(){ int s; scanf("%d", &s); return s; } #include using namespace std; int main(){ const int n = getInt(); const int c = getInt(); const int v = getInt(); vector s(v); vector t(v); vector y(v); vector m(v); REP(i,v) s[i] = getInt() - 1; REP(i,v) t[i] = getInt() - 1; REP(i,v) y[i] = getInt(); REP(i,v) m[i] = getInt(); vector, pair > > g(v); REP(i,v) g[i] = make_pair(make_pair(s[i], t[i]), make_pair(y[i], m[i])); sort(g.begin(), g.end()); const int inf = 100000000; vector > dp(n, vector(c + 1, inf)); dp[0][c] = 0; REP(i,v){ const int ss = g[i].first.first; const int tt = g[i].first.second; const int yy = g[i].second.first; const int mm = g[i].second.second; REP(j,c+1) if(dp[ss][j] != inf && j - yy >= 0){ dp[tt][j - yy] = min(dp[tt][j - yy], dp[ss][j] + mm); } } int ans = inf; REP(i,c+1) ans = min(ans, dp[n - 1][i]); ans = (ans == inf ? -1 : ans); printf("%d\n", ans); return 0; }