------
## 最终结论
```python
def maxProfit(prices):
    if not prices:
        return 0

    n = len(prices)
    hold = [0] * n
    cooldown = [0] * n
    rest = [0] * n

    hold[0] = float('-inf')  # Initial state: cannot hold stock on day 0
    cooldown[0] = 0           # No profit on cooldown on day 0
    rest[0] = 0               # No profit resting on day 0

    for i in range(1, n):
        hold[i] = max(hold[i - 1], rest[i - 1] - prices[i])
        cooldown[i] = hold[i - 1] + prices[i]
        rest[i] = max(rest[i - 1], cooldown[i - 1])

    return max(cooldown[n - 1], rest[n - 1])

# Example usage:
print(maxProfit([1, 2, 3, 0, 2])) # Output: 3
```