simple solution using multiset c++
since, set removes duplicates of a number , we have to use multiset.\n# Code\n\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& vals, vector<vector<i
since, set removes duplicates of a number , we have to use multiset.\n# Code\n```\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {\n        int n=vals.size();\n        vector<multiset<int>> v(n);\n        for(auto &vec: edges){\n            int first=vec[0],second=vec[1];\n            v[first].insert(-vals[second]); //negative, in order to store numbers in non-increasing order\n            v[second].insert(-vals[first]);\n        }\n        \n        int ans=INT_MIN;\n        for(int i=0;i<n;i++){\n            int cnt=0;\n            int sum=vals[i];\n            for(auto &K: v[i]){\n                if(K>0 || cnt==k) break;\n                sum-=K;\n                cnt++;\n            }\n            ans=max(ans,sum);\n        }\n        \n        return ans;\n    }\n};\n```
['C++']