Getting TLE in last testcase

ques:
https://hack.codingblocks.com/contests/c/547/908

code: https://ide.codingblocks.com/s/46442

Adding all the possible combinations to heap and then checking for duplicates is not desired because this is quite similar to using maps and thus it is showing TLE.
Here is my solution for your reference:
https://ide.codingblocks.com/s/46640