the solution of the MaxProfit