Before the gates of the lily shoals of Padmore close for winter, Theo must finish the queues ledger - one figure at a time. Task: Prices over n days; buy once and sell once later. Print the maximum profit (0 if none). Input format: First line: n. Second line: n prices. Output format: Print the maximum profit. Constraints: 1 <= n <= 4000; 0 <= price <= 10^9.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= n <= 4000; 0 <= price <= 10^9.
