[Solution] Doremy's City Construction Codeforces Solution
Doremy's new city is under construction! The city can be regarded as a simple undirected graph with vertices. The -th vertex has altitude . Now Doremy is deciding which pairs of vertices should be connected with edges.
Due to economic reasons, there should be no self-loops or multiple edges in the graph.
Due to safety reasons, there should not be pairwise distinct vertices , , and such that and the edges and exist.
Under these constraints, Doremy would like to know the maximum possible number of edges in the graph. Can you help her?
Note that the constructed graph is allowed to be disconnected.
The input consists of multiple test cases. The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the number of vertices.
The second line of each test case contains integers () — the altitudes of each vertex.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output the maximum possible number of edges in the graph.
No comments:
Post a Comment