C++ priority queue with explanation
\n    class Solution {\n    public:\n        using P = pair<long long, int>;\n        int nthSuperUglyNumber(int n, vector<int>& primes) {\n            vector<i
```\n    class Solution {\n    public:\n        using P = pair<long long, int>;\n        int nthSuperUglyNumber(int n, vector<int>& primes) {\n            vector<int> index(primes.size(), 0);\n            vector<long long> nums;\n            nums.push_back(1);      \n            \n            priority_queue<P, vector<P>, greater<P>> pq;    // remember pair(the ugly number, who generated this ugly)\n            for (int i = 0; i < primes.size(); i++)\n                pq.emplace(primes[i], i);   // initial ugly = prime  * 1\n            \n            while (nums.size() < n)\n            {\n                auto [value, id] = pq.top();    // get the smallest ugly\n                pq.pop();\n                \n                if (value != nums.back())       // check the dupe\n                    nums.push_back(value);\n                \n                index[id]++;                             // the prime generated this small ugly number should move forward to multiply next ugly number\n                pq.emplace(nums[index[id]] * primes[id], id);         // push the new ugly number to pq to participate sorting\n            }\n            \n            return nums.back();\n        }\n    };\n```
['C', 'Heap (Priority Queue)']