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=∑Stretch(u, v), for all u, v such that u<v and u, v are leaf nodes in the tree.
Stretch(u,v) is defined as: (Sum of values of nodes present on simple path between node u and v) * (Length of the simple path)
Please note:
Input
Output
Constraints
2≤N≤10001≤A[i]≤104
Verdit and Scoring
For the given test case: