PIZZA DELIVERY DP PROBLEM

i am getting TLE in this problem can anybody say what approach i should change to avoid it?
my solution
https://www.codechef.com/viewsolution/26222892

m = max(H)
for(int i=0;i<n;i++){
for(int j=1;j<=m*2;j++){
if(j>=K[i]){
A[j] = min(A[j],1+A[j-K[i]]);
}
}
}
for(int i=0;i<n;i++){
total+=A[H[i]*2];
}

bro thanks for your approach but can you tell me what i am doing wrong?
@lx_lovin

1 Like

@adi521 you are calculating for every i of H which takes almost O(n^3) complexity

got it man thanks @lx_lovin