Getting Time limit error

my solution -https://codeforces.com/contest/1345/submission/94883674

question -https://codeforces.com/contest/1345/problem/B

please tell me why i am getting TLE as i am getting correct ans in test cases

hello @shivamgoel150

try ur code for this->
1
1736264

also the second argument of ur upper bound is not correct, it should be dp+size (u r using dp+n)

sir i corrected the upper bound statement and still getting TLE, can you please tell me how to correct my code, i am totally confused why this is happening

@shivamgoel150
check now->

made following changes->
size of dp was not correct, u need to use separate variable that will hold count of valid entries in ur dp array.
also u need to break while loop if it-1 <0