Easy To Understand | Java Solution | List Sort
Approach\n-Create a List of type array {element, index}.\n-Fill it from nums and Sort it based on elements and also calculate the total sum of all elements.\n-I
# Approach\n-Create a List of type array {element, index}.\n-Fill it from nums and Sort it based on elements and also calculate the total sum of all elements.\n-Iterate the queries and One by one mark elements by 0. As all elements in nums are greater than 1 so 0 wont effect the sum.\nFirst Mark nums array from Query[].\nIterate the sorted list and start marking the elements and subtract the elements from Sum if not unmarked.\nLast push sum into result array.\n\n# Complexity\n- Time complexity:\nO(m*n)\n\n# Code\n```java []\nclass Solution {\n    public long[] unmarkedSumArray(int[] nums, int[][] queries) {\n        \n        long[] result = new long[queries.length];\n        \n        List<int[]> listSort = new ArrayList();\n\n        long sum = 0;\n\n        for(int i = 0 ; i < nums.length;i++){\n            listSort.add(new int[]{nums[i],i});\n            sum += nums[i];\n        }\n\n        int listSortInd = 0;\n\n        Collections.sort(listSort,(a,b) -> Integer.compare(a[0],b[0]));\n\n        for(int i = 0 ; i < queries.length; i ++){\n           \n           int one = queries[i][0];\n           int two = queries[i][1];\n\n            sum -= nums[one];\n            nums[one] = 0;\n             // Iterate over the array\n           for (int f = listSortInd; f < listSort.size() && two > 0; f++) {\n\n              int element = listSort.get(f)[0];  \n              int elementInx = listSort.get(f)[1];\n              \n              if(nums[elementInx] >0){\n                sum -= nums[elementInx];\n                nums[elementInx] = 0;\n                two--;\n                listSortInd++;\n              }\n             \n            }\n        result[i] = sum;\n        }\n        return result;\n    }\n}\n```
['Java']