C# | Sort
\n# Code\n\npublic class Solution \n{\n    public int MaxStarSum(int[] vals, int[][] edges, int k)\n    {\n        int n = vals.Length;\n        List<int>[] neg
\n# Code\n```\npublic class Solution \n{\n    public int MaxStarSum(int[] vals, int[][] edges, int k)\n    {\n        int n = vals.Length;\n        List<int>[] neghbours = new List<int>[n];\n        for (int i = 0; i < n; i++)\n        {\n            neghbours[i] = new List<int>();\n        }\n        foreach (var edge in edges)\n        {\n            neghbours[edge[0]].Add(vals[edge[1]]);\n            neghbours[edge[1]].Add(vals[edge[0]]);\n        }\n\n        int sumMax = int.MinValue;\n        for (int i = 0; i < n; i++)\n        {\n            int curSum = vals[i];\n            curSum += neghbours[i].OrderByDescending(n => n).Take(k).Where(n => n > 0).Sum();\n            sumMax = Math.Max(sumMax, curSum);\n        }\n        return sumMax;\n    }\n}\n```
['C#']