```
typedef vector<int> vi;
class Solution {
public:
int maxProfit(vector<int>& prices) {
if(prices.empty()) return 0;
int n = (int)prices.size();
vi prof(n,0);
for(int r=0;r<2;++r){
for(int i=1,m=prof[0]-prices[0];i<n;++i){
m = max(m,prof[i]-prices[i]);
prof[i] = max(prof[i-1],prices[i]+m);
}
}
return prof[n-1];
}
};
```

The `prof`

vector is storing the profit. `prof[i]`

the maximum profit a person can get up to the ith day with at most r+1 transactions. And iterate r from 0 to 2-1.