```
int maxProfit(int k, vector<int>& prices) {
int len = prices.size();
if (len<2) return 0;
if (k>len/2){ // simple case
int ans = 0;
for (int i=1; i<len; ++i){
ans += max(prices[i] - prices[i-1],0);
}
return ans;
}
int hold[k+1];
int rele[k+1];
for (int i=0;i<=k;++i){
hold[i] = INT_MIN;
rele[i] = 0;
}
int cur;
for (int i=0; i<len; ++i){
cur = prices[i];
for(int j=1; j<=k; ++j){
rele[j] = max(rele[j],hold[j] + cur);
hold[j] = max(hold[j],rele[j-1] - cur);
}
}
return rele[k];
}
```

The last few steps:

```
for(int j=1; j<=k; ++j){
rele[j] = max(rele[j],hold[j] + cur);
hold[j] = max(hold[j],rele[j-1] - cur);
}
```

My opinion is j is supposed to be started with k and ended up with 1, like code below:

```
for(int j=k; j>0; --j){
rele[j] = max(rele[j],hold[j] + cur);
hold[j] = max(hold[j],rele[j-1] - cur);
}
```

However, the perious one get accepted. I'm comfused, Can anyone make it through?