public static int MaxPeople(int[] heights, int[] weights) { int n = heights.Length; int[] depths = new int[n]; for (int i = 0; i < n; i++) { CircusTowerClass.MaxDepth(heights, weights, n, i, depths); } return(depths.Max()); }
private static int MaxDepth(int[] heights, int[] weights, int n, int current, int[] depths) { if (depths[current] > 0) { return(depths[current]); } depths[current] = 1; for (int i = 0; i < n; i++) { if (heights[current] > heights[i] && weights[current] > weights[i]) { depths[current] = Math.Max(depths[current], 1 + CircusTowerClass.MaxDepth(heights, weights, n, i, depths)); } } return(depths[current]); }