PDP-27 (2015) - Camp common - 3 (maxdiff)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 1M

Author:
Problem type
Allowed languages
C, C++, Java, Pascal, Python

MAXDIFF

You are given a sequence of N natural numbers: a_1, a_2, ..., a_N. The maximum value of the difference a_i - a_j is requested, where a_i and a_j are two terms of the sequence and i < j.

Input

The program reads data from the text file "maxdiff.in". The first line contains an integer N, which is the number of terms in the sequence. The second line contains the N natural numbers a_1, a_2, ..., a_N separated in pairs by spaces.

Ouput

The result must be printed to the text file "maxdiff.out". Only one line should be printed containing a natural number: the maximum value of the difference a_i - a_j, where a_i and a_j are terms of the sequence and i < j.

Constraints

1 \le N \le 1.000.000

Time limit: 1 sec.
Maximum Available Memory: 1 MB.

Example of Input - Output

STDIN (maxdiff.in)

10
3 12 3 0 28 9 13 4 23 7

STDOUT (maxdiff.out)

24

Comments

There are no comments at the moment.