Maximum of minima

Write a function

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

that returns
max_(0 ≤ i < j < n){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⁹ is 10¹⁰.

Precondition

@V@ has between 2 and 10⁵ numbers, all between 0 and 10⁹.

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.

Problem information

Author: Javier Nistal

Generation: 2026-01-25T10:39:11.465Z

© Jutge.org, 2006–2026.
https://jutge.org
