All problems

The Worst Fall

hardPythonTime SeriesLoops

Halcyon's risk officer never asks how a fund finished the year. She asks how much a client could have lost by buying at the worst moment and selling at the worst moment after that. That figure, not the final return, is what decides whether the phones start ringing during a bad fortnight.

Task: Print the largest fall from an earlier high to a later value.

Input

The first line holds an integer n, the number of days. Each of the next n lines holds one day's value.

Output

One line: the size of that fall, in the same units as the input, with exactly one digit after the decimal point. The high has to come before the low, and a later recovery to a new high does not cancel an earlier fall. A series that never falls prints 0.0.

Example:

Input:
4
100
80
90
70

Output:
30.0

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…