Simple intution based question
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public long findMaximumElegance(int[][] items, int k) \n    {\n        Arrays.sort(items, (a,b) -> ( b[0]-a[0]));\n        int n = items.length;\n        HashSet<Integer> visitedCategory = new HashSet<>();\n        ArrayList<Long> duplicatValue = new ArrayList<>();\n        long ans = 0;\n\n        for(int i=0; i<k; i++)\n        {\n            int currCat = items[i][1];\n            long currVal = items[i][0];\n            ans +=currVal;\n\n            if(visitedCategory.contains(currCat))\n            {\n                duplicatValue.add(currVal);\n            }\n            else\n            {\n                visitedCategory.add(currCat);\n            }\n        }    \n        long curr = ans;\n        ans = ans + 1L * visitedCategory.size()*visitedCategory.size();\n        for(int i=k; i<n; i++)\n        {\n            int currCat = items[i][1];\n            int currVal = items[i][0];\n\n            if(duplicatValue.size()==0) break;\n            if(!visitedCategory.contains(currCat))\n            {\n                visitedCategory.add(currCat);\n                curr = curr + currVal - duplicatValue.remove(duplicatValue.size()-1);\n                ans = Math.max(ans, curr + 1L * visitedCategory.size()*visitedCategory.size());\n            }\n        }\n        return ans;\n    }\n}\n```
['Sorting', 'Ordered Set', 'Java']