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];

}

1 Like