Write a function

long long maxmin(const vector<long long>& V);

that returns

| ⎧ ⎨ ⎩ | min(V[i], V[j]) × (j − i) | ⎫ ⎬ ⎭ | . |

For instance, the answer for [9, 7, 4, 1] is 8,
corresponding to the numbers 9 and 4,
which are at distance 2.
As another example, the answer for a vector with eleven 10^{9}
is 10^{10}.

Precondition

*V* has between 2 and 10^{5} numbers,
all between 0 and 10^{9}.

Observation

The expected solution has cost Θ(V.size()), with a small constant.

Observation You only need to submit the required procedure; your main program will be ignored.

Information

- Author
- Javier Nistal
- Language
- English
- Official solutions
- C++
- User solutions
- C++