#K77077. Maximum Rental Savings

    ID: 34784 Type: Default 1000ms 256MiB

Maximum Rental Savings

Maximum Rental Savings

You are given an array of rental prices over N days. The task is to choose two distinct days such that the second day comes after the first, and the difference between the rental price on the second day and the rental price on the first day is maximized. In mathematical terms, for an array \( arr[0], arr[1], \dots, arr[N-1] \), you need to find the maximum value of \( arr[j] - arr[i] \) for all \( 0 \le i < j < N \). If no such pair exists that yields a positive difference, the answer should be 0.

Note: All formulas are written in \( \LaTeX \) format.

inputFormat

The first line of the input contains an integer \(N\) representing the number of days. The second line contains \(N\) space-separated integers, each indicating the rental price for a day.

outputFormat

Output a single integer representing the maximum savings achievable by renting on two different days (where the second day is later than the first). If no positive savings can be achieved, output 0.

## sample
6
7 1 5 3 6 4
5