Help in solving IPCTRAIN

Need help! Below is my link to code. It is passing Subtask 1 completely but fails in SubTask 2. Can Anyone please help me where am i doing wrong.

https://www.codechef.com/viewplaintext/18941549