using System; using System.Linq; using System.Collections.Generic; class No628 { static void Main() { var gazouCount = Int32.Parse(Console.ReadLine()); SortedDictionary gazouDic = new SortedDictionary(); for (int i = 0; i < gazouCount; ++i) { Console.ReadLine();//画像番号 var tagNum = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var tagStr = Console.ReadLine().Split(' '); for (int j = 0; j < tagNum[0]; ++j) { if (!gazouDic.ContainsKey(tagStr[j])) { gazouDic.Add(tagStr[j], tagNum[1]); } else { int value; gazouDic.TryGetValue(tagStr[j], out value); gazouDic[tagStr[j]] = value + tagNum[1]; } } } var count = 0; var answer = gazouDic.OrderBy((x) => x.Value); foreach (var a in answer) { Console.WriteLine($"{a.Key} {a.Value}"); if (count++ >= 10) break; } } }