public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var emp = new List <int> [N]; for (int i = 0; i < N; ++i) { emp[i] = new List <int>(); } for (int i = 0; i < N - 1; ++i) { emp[cin.ReadInt - 1].Add(i + 1); } var salary = new int[N]; Func <int, int> f = null; f = (int i) => { if (salary[i] != 0) { return(salary[i]); } if (emp[i].Count == 0) { return(1); } var min = int.MaxValue; var max = 0; foreach (var x in emp[i]) { min = Min(f(x), min); max = Max(f(x), max); } return(salary[i] = (min + max) + 1); }; WriteLine(f(0)); }
public void Solve(ConsoleInput cin) { checked { var N = cin.ReadInt; var red = new List <Point>(); var blue = new List <Point>(); for (int i = 0; i < N; ++i) { red.Add(new Point(cin.ReadInt, cin.ReadInt)); } for (int i = 0; i < N; ++i) { blue.Add(new Point(cin.ReadInt, cin.ReadInt)); } var r = red.OrderByDescending(p => p.y).ThenByDescending(p => p.x).ToArray(); var b = blue.OrderBy(p => p.x).ThenBy(p => p.y).ToArray(); var used = new bool[N]; var cnt = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (r[i].x < b[j].x && r[i].y < b[j].y && !used[j]) { cnt++; used[j] = true; break; } } } WriteLine(cnt); } }
public void Solve(ConsoleInput cin) { var A = cin.ReadIntArray(5).Combinations(3).Select(x => x.Sum()).OrderByDescending(x => x).ToList(); WriteLine(A[2]); }