Messy Java sol. || O(n^2)
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:$$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimport java.util.*;\nclass Solution {\n    public static HashMap<Integer, Integer>\n    sortByValue(HashMap<Integer, Integer> hm)\n    {\n        // Create a list from elements of HashMap\n        List<Map.Entry<Integer, Integer> > list\n            = new LinkedList<Map.Entry<Integer, Integer> >(\n                hm.entrySet());\n \n        // Sort the list using lambda expression\n        Collections.sort(\n            list,\n            (i1,\n             i2) -> i1.getValue().compareTo(i2.getValue()));\n \n        // put data from sorted list to hashmap\n        HashMap<Integer, Integer> temp\n            = new LinkedHashMap<Integer, Integer>();\n        for (Map.Entry<Integer, Integer> aa : list) {\n            temp.put(aa.getKey(), aa.getValue());\n        }\n        return temp;\n    }\n    \n    public long[] unmarkedSumArray(int[] nums, int[][] que) {\n        \n        long[]ans=new long[que.length];        \n        HashMap<Integer,Integer> map=new HashMap<>();\n        for(int j=0;j<nums.length;j++){\n           map.put(j,nums[j]);\n        }\n\n        HashMap<Integer, Integer> map2=sortByValue(map);\n        for(int i=0;i<que.length;i++){\n           \n            if(map2.containsKey(que[i][0]))\n                map2.remove(que[i][0]);\n           \n            for(int j=0;j<que[i][1];j++){\n               \n                if(map2.size()>0){\n                    \n                    for (Map.Entry<Integer,Integer> mapElement : map2.entrySet()) {\n                        int key = mapElement.getKey();\n                        map2.remove(key);\n                        break;\n                    }\n                }\n            }\n            long sum=0;\n            for(int val:map2.values()){\n                sum=sum+val;\n            }            \n            ans[i]=sum;            \n        }\n        return ans;\n    }\n}\n```
['Java']