#include using namespace std; #define INF 1e9 #define FOR(i,a,b) for(int i=a;i>N>>C>>V; vector S(V),T(V),Y(V),M(V); 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, 51)rep(j, 301) dp[i][j] = INF; //rep(i,310)dp[1][i]=0; dp[1][C]=0; for(int i=1;i<=N;i++){ for(int j=0;j<=C;j++){ for(int k=0;k=0){ dp[T[k]][j-Y[k]]=min(dp[i][j]+M[k],dp[T[k]][j-Y[k]]); } } } } } int ans=INF; rep(i,301)ans=min(ans,dp[N][i]); if(ans