Maximum of minima P38906


Statement
 

pdf   zip   main.cc

thehtml

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 109 is 1010.

Precondition

V has between 2 and 105 numbers, all between 0 and 109.

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++