cswork / OA打开练习工作台

CiscoOA #22

Find Maximum Difference

估计简单可在线判题

考点(AI 标注)股票买卖原地数组

Among element pairs with i<j and a[j]>a[i], find the maximum of a[j]−a[i]; if there is no valid pair, output 0.

输入格式

The input is n followed by n integers. The original had no numeric bounds; this site adds 0≤n≤200000 and elements in −10^9..10^9; an empty array also outputs 0.

输出格式

Output a single integer, the answer.

样例 1

输入:

6
7 1 5 3 6 4

输出:

5

样例 2

输入:

3
9 7 4

输出:

0

样例 3

输入:

0

输出:

0

样例说明

The outputs of the three public examples are, in order: 5; 0; 0. Verified by independent enumeration or direct simulation.