using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Magatro { static int N, C, V; static int[] S, T, Y, M; static void Main() { Read(); long[,] dp = new long[N+1, C + 1]; for(int i = 0; i < N + 1; i++) { for(int j = 0; j < C + 1; j++) { dp[i, j] = int.MaxValue; } } dp[1, 0] = 0; for(int i = 1; i <= N; i++) { for(int j = 0; j < V; j++) { if (S[j] == i) { for(int q = 0; q <= C; q++) { if (dp[i, q] != int.MaxValue) { if (q + Y[j] <= C) { dp[T[j], q + Y[j]] = Math.Min(dp[i, q] + M[j], dp[T[j], q + Y[j]]); } } } } } } long min = int.MaxValue; bool a = true ; for(int i = 0; i <= C; i++) { if (dp[N, i] != int.MaxValue) { min = Math.Min(min, dp[N, i]); a = false; } } if (a) { min = -1; } Console.WriteLine(min); } static void Read() { N = int.Parse(Console.ReadLine()); C = int.Parse(Console.ReadLine()); V = int.Parse(Console.ReadLine()); S = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); T = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); Y = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); M = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); } }