I have been trying this question for quite long but again and again getting tle or wa

please help me I know another approach might be bfs with priority queue but how can i optimize this one

In the solution above dp[i][j] stores minimum number of moves req to reach ith index from start with j bullets
memo[i] has been used to store the minimum bullets req to reach the ith index so that if bullets available are greater then memo[i] then i can directlt return the answer of dp[i][memo[i]]
please help me with this approach and rectify my code