Maximum of minima P38906


Statement
 

pdf   zip   main.cc

Write a function

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

that returns max0i<j<n{min(V[i],V[j])×(ji)}.\max_{0 \le i < j < n} \left\{ \min(V[i], V[j]) \times (j - i) \right\} \enspace .

For instance, the answer for [9,7,4,1][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 10910^9 is 101010^{10}.

Precondition

@V@ has between 2 and 10510^5 numbers, all between 0 and 10910^9.

Observation

The expected solution has cost Θ(V.size())\Theta(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++