getting tle SANSKAR

this code was accepted but only when intensity of sanskar ≤ 10^5, but when i converted int to long long for intensity of sanskar ≤ 10^10 it gave tle.
Can anybody tell how to optimize it further ,i have used backtracking approach
here is link to my code

1 Like

what is the question?

1 Like

Please try reading this :

@skbly7 the editorial is based on dynamic approach but i am trying backtracking approach

@anupam_datta the question is http://www.codechef.com/problems/SANSKAR

//