using System.Collections.Generic; using System.Linq; 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 x = int.Parse(line[2]); var d = new Dictionary>(); for (int i = 0; i < n; i++) { line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); if (!d.ContainsKey(b)) d[b] = new List(); d[b].Add(a); } var s = new long[n]; var p = 0; foreach (var y in d) { var first = true; foreach (var z in y.Value.OrderByDescending(z => z)) { if (first) { s[p++] = z + x; first = false; } else s[p++] = z; } } Array.Sort(s); Array.Reverse(s); for (int i = 1; i < n; i++) s[i] = s[i] + s[i - 1]; Console.ReadLine(); line = Console.ReadLine().Trim().Split(' '); var c = Array.ConvertAll(line, int.Parse); var ans = 0L; foreach (var y in c) ans += s[y - 1]; Console.WriteLine(ans); } }