[C++ / Go] Sort only - O(nlogn) solution
Approach\n- We create a sorted copy of nums with pair of value and index. This helps efficiently mark smallest unmarked elements using index attribute.\n\n# Cod
# Approach\n- We create a sorted copy of `nums` with pair of value and index. This helps efficiently mark smallest unmarked elements using `index` attribute.\n\n# Code\n```C++ []\nclass Solution {\npublic:\n    vector<long long> unmarkedSumArray(vector<int>& nums, vector<vector<int>>& queries) {\n        int n = nums.size();\n        long long sum = 0;\n        vector<pair<int, int>> pairs(n);\n\n        // Create copy of nums and calculate total sum\n        for (int i = 0; i < n; i++) {\n            sum += nums[i];\n            pairs[i] = {i, nums[i]};\n        }\n\n        // Sort the new array\n        sort(pairs.begin(), pairs.end(), \n        [](const pair<int, int>& x, const pair<int, int>& y) {\n            if (x.second == y.second) {\n                return x.first < y.first;\n            }\n            return x.second < y.second;\n        });\n\n        vector<bool> marked(n, false);\n        int m = queries.size();\n        vector<long long> res(m);\n\n        // Iterator of new array for smallest value\n        int cur = 0; \n\n        for (int i = 0; i < m; i++) {\n            int deleteId = queries[i][0];\n            int k = queries[i][1];\n\n            // Mark if target index isn\'t marked.\n            if (!marked[deleteId]) {\n                marked[deleteId] = true;\n                sum -= nums[deleteId];\n            }\n\n            // Get k smallest values\n            while (k > 0 && cur < n) {\n                int id = pairs[cur].first;\n                int val = pairs[cur].second;\n\n                if (!marked[id]) {\n                    marked[id] = true;\n                    sum -= val;\n                    k--;\n                }\n                cur++;\n            }\n\n            res[i] = sum;\n        }\n\n        return res;\n    }\n};\n```\n```Go []\ntype Pair struct {\n    id int\n    val int\n}\n\nfunc unmarkedSumArray(nums []int, queries [][]int) []int64 {\n    n := len(nums)\n    sum := int64(0)\n    pairs := make([]Pair, n)\n\n    // Create copy of nums and calculate total sum\n    for id, val := range nums {\n        sum += int64(val)\n        pairs[id] = Pair{id : id, val: val}\n    }\n\n    // Sort the new array\n    sort.Slice(pairs, func(x, y int)bool {\n        if pairs[x].val == pairs[y].val {\n            return pairs[x].id < pairs[y].id\n        }\n        return pairs[x].val < pairs[y].val;\n    })\n\n    marked := make([]bool, n)\n    res := make([]int64, len(queries))\n\n    // Iterator of new array for smallest value\n    cur := 0\n\n    for i, query := range queries {\n        deleteId := query[0]\n        k := query[1]\n\n        // Mark if target index isn\'t marked.\n        if !marked[deleteId] {\n            marked[deleteId] = true\n            sum -= int64(nums[deleteId])\n        }\n\n        // Get k smallest values\n        for ; k > 0 && cur < n; cur++ {\n            pair := pairs[cur]\n\n            if id, val := pair.id, pair.val; !marked[id] {\n                marked[id] = true\n                sum -= int64(val)\n                k--\n            }\n        }\n\n        res[i] = sum\n    }\n\n    return res\n}\n```\n\n# Complexity\n- Time complexity: $O(nlogn)$\n- Space complexity: $O(n)$
['Sorting', 'C++', 'Go']