Find maximum difference

Divide and Conquer

Given an array A, write a program to find the max(A[j]-A[i]) where i < j. If max(A[j]-A[i])<0, output 0. The input will start with an integer n, which indicates the length of the given array. The next line will be the array.

Example 1

Input:
2
1 5
Output:
4

Example 2:

Input:
4
1 5 8 2
Output:
7

Example 3:

Input:
6
8 7 4 3 2 1
Output:
0