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=i=N∑i=1[j=N∑j=i+1[F(i,j)]], where F(i,j)=LIS(i,j)×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≤N≤5001≤A[i]≤109
Verdit and Scoring
For the given test case:
Hence, score is equal to 8.