Getting tle in one case

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

since the input is quite large you need to use fast i/o. So add
ios_base::sync_with_stdio(false);
cin.tie(NULL)
in the begining of your code
Corrected code