Note: This is an approximate problem. There is no exact solution. You must find the most optimal solution. Please, take a look at the sample explanation to ensure that you understand the problem correctly.
Problem statement
Given a set of N nodes, where each node has an integer A[i] associated with it.
Construct a tree using N nodes such that the value of the given function Z is maximized.
\(Z = \sum_\limits{i = 1}^{i = N} [\sum_\limits{j = i + 1}^{j = N}[F(i,j)]]\), where \(F(i,j) = LIS(i,j) \times LDS(i,j)\)
here \(LIS(i,j) \) represents length of longest increasing subsequence on simple path starting from node i to node j and \(LDS(i,j)\) represents length of longest decreasing subsequence on simple path starting from node i to node j .
Input
Output
Constraints
\(2 \le N \le 500 \\ 1 \le A[i] \le 10^9\)
Verdit and Scoring
For the given test case:
Hence, score is equal to 8.