void Solve(StreamScanner ss, StreamWriter sw) { //--------------------------------- N = ss.Next(int.Parse); W = ss.Next(long.Parse); G = ss.Next(long.Parse, 2, N) .Select(a => new WeightValuePair(a[0], a[1])) .GroupBy(wv => wv.Weight) .OrderBy(g => g.Key) .Select(g => g.OrderByDescending(wv => wv.Value).ToArray()) .ToArray(); sw.WriteLine(GetAns(0, 0, 0)); //--------------------------------- }