#include #include #include #include using namespace std; int n; int costs[51][51]; int times[51][51]; int scan(int city, int cost, int time) { if (city == n) { return time; } int minTime = numeric_limits::max(); for (int next = city + 1; next <= n; ++next) { if (costs[city][next] != numeric_limits::max()) { if (costs[city][next] <= cost) { minTime = min(minTime, scan(next, cost - costs[city][next], time + times[city][next])); } } } return minTime; } int main() { int c, v; cin >> n >> c >> v; vector s(v); for (int i = 0; i < v; ++i) { cin >> s[i]; } vector t(v); for (int i = 0; i < v; ++i) { cin >> t[i]; } vector y(v); for (int i = 0; i < v; ++i) { cin >> y[i]; } vector m(v); for (int i = 0; i < v; ++i) { cin >> m[i]; } fill(&costs[0][0], &costs[n][n] + 1, numeric_limits::max()); fill(×[0][0], ×[n][n] + 1, numeric_limits::max()); for (int i = 0; i < v; ++i) { costs[s[i]][t[i]] = y[i]; times[s[i]][t[i]] = m[i]; } int result = scan(1, c, 0); cout << ((result == numeric_limits::max()) ? -1 : result) << endl; return 0; }