Hostel visit heap

answer link:https://ide.codingblocks.com/s/54607
Question link:https://hack.codingblocks.com/contests/c/471/1629

Please tell why for second test case, it is giving wrong answer.