Prob A
Prob A
EASY PROBLEM
Michael just learned about Absolute value and its properties. He also thinks mathematics is his
instinct so after school, he usually tries to come up with new problem to practice and sharpen his
skill. Today, after solving all homework, to kill his boredom, he finds a very strange problem:
Given an array of N integers, X1, X2, … XN. Find the maximum value of:
|Xi – Xj| + |i – j|, for 1 ≤ i, j ≤ N
Input
- The first line is the number N, 2 ≤ N ≤ 1.000.000
- The next line contains N elements of array, |Xi| ≤ 108, for 1 ≤ i ≤ N
Output
Maximum value of the function defined above.
Examples
Standard Input Standard Output
4 12
2 -1 5 9
Explain:
Choose X2 = -1 and X4 = 9.
|-1-9| + |2-4| = 12