#P5146. 最大差值

最大差值

Problem Description

HKE has recently been keen on studying sequences, and once he discovered an interesting problem:

For a sequence A1,A2,⋯ ,AnA_1,A_2,\cdots,A_n, find two indices i,ji, j (1≤i<j≤n1\le i<j\le n) such that Aj−AiA_j-A_i is maximized.

Given this sequence, please find the maximum value of Aj−AiA_j-A_i.

Input Format

The first line contains a positive integer nn. The next nn lines each contain one integer. The integer on the (i+1)(i + 1)-th line is AiA_i.

Output Format

One line, the maximum value of Aj−AiA_j-A_i.

10
1
3
4
6
7
9
10
1
2
9
9

Hint

Constraints

  • For 30%30\% of the testdata, n≤1000n\le1000.
  • For 70%70\% of the testdata, n≤105n\le10^5.
  • For 100%100\% of the testdata: 2≤n≤1062\le n\le 10^6, and AiA_i is within the int range.

Translated by ChatGPT 5