using static System.Math; using System; public class Hello { static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var m = int.Parse(line[1]); var k = int.Parse(line[2]); line = Console.ReadLine().Trim().Split(' '); var c = Array.ConvertAll(line, x => int.Parse(x) - 1); line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); getAns(n, m, k, c, a); } static void getAns(int n, int m, int k, int[] c, int[] a) { var d = new int[m]; for (int i = 0; i < k; i++) d[c[i]]++; var ans = long.MaxValue; for (int i = 0; i < m; i++) { if (d[i] == k) { Console.WriteLine(0); return; } var tempcost = (k - d[i]) * (long)a[i]; ans = Min(ans, tempcost); } for (int i = 0; i < n - k; i++) { d[c[i]]--; d[c[i + k]]++; var tempcost = (k - d[c[i + k]]) * (long)a[c[i + k]]; ans = Min(ans, tempcost); if (ans == 0) { Console.WriteLine(0); return; } } Console.WriteLine(ans); } }