C++ Solution using pairs, sorting beats 99%
Intuition\n Describe your first thoughts on how to solve this problem. \nHere\'s the logic behind the code explained in a few simple steps:\n\n1. Initialization
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nHere\'s the logic behind the code explained in a few simple steps:\n\n1. **Initialization**:\n   - Create a vector `v` of pairs where each pair contains the index and value from the `nums` array.\n   - Initialize a `mark` vector of the same size as `nums` to keep track of which elements have been marked (initially all set to 0, meaning unmarked).\n\n2. **Sorting**:\n   - Sort the vector `v` based on the values in `nums`. If two values are the same, sort them by their index. This helps in marking the smallest values first and, in case of ties, the smallest indices.\n\n3. **Calculate Total Sum**:\n   - Compute the sum of all elements in `nums` and store it in `total`.\n\n4. **Processing Queries**:\n   - For each query, perform the following steps:\n     - **Mark the Specified Index**: If the element at the given index is not already marked, mark it and subtract its value from `total`.\n     - **Mark `k` Smallest Unmarked Elements**: Iterate through the sorted vector `v` and mark the smallest unmarked elements until `k` elements are marked. Subtract their values from `total`.\n     - Add the updated `total` to the answer vector `ans`.\n\n5. **Return Results**:\n   - After processing all the queries, return the `ans` vector, which contains the sum of unmarked elements after each query. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O((N+Q)(Log(N)))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<long long> unmarkedSumArray(vector<int>& nums, vector<vector<int>>& queries) {\n        vector<long long> ans; \n        vector<pair<int, int>> v;\n        const int n = nums.size();\n        vector<int> mark(n, 0);\n        int i;\n\n        for (i = 0; i < nums.size(); i++) {\n            v.push_back({i, nums[i]});\n        }\n\n        sort(v.begin(), v.end(), [](const std::pair<int, int>& a, const std::pair<int, int>& b) {\n            if (a.second == b.second)\n                return a.first < b.first;\n            return a.second < b.second;\n        });\n\n        long long total = accumulate(nums.begin(), nums.end(), 0LL);\n        int j=0;\n        for (i = 0; i < queries.size(); i++) {\n            int index = queries[i][0];\n            int k = queries[i][1];\n\n            if (mark[index] != 1) {\n                mark[index] = 1;  \n                total -= nums[index];\n            }\n\n            int markedCount = 0;\n            while (j < v.size() && markedCount < k) {\n                if (mark[v[j].first] != 1) {\n                    mark[v[j].first] = 1; \n                    total -= v[j].second;\n                    markedCount++;         \n                }\n                 j++;\n            }\n\n            ans.push_back(total);\n        }\n\n        return ans;\n    }\n};\n\n```
['C++']