CF1656F.Parametric MST

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given nn integers a1,a2,,ana_1, a_2, \ldots, a_n . For any real number tt , consider the complete weighted graph on nn vertices Kn(t)K_n(t) with weight of the edge between vertices ii and jj equal to wij(t)=aiaj+t(ai+aj)w_{ij}(t) = a_i \cdot a_j + t \cdot (a_i + a_j) .

Let f(t)f(t) be the cost of the minimum spanning tree of Kn(t)K_n(t) . Determine whether f(t)f(t) is bounded above and, if so, output the maximum value it attains.

输入格式

The input consists of multiple test cases. The first line contains a single integer TT ( 1T1041 \leq T \leq 10^4 ) — the number of test cases. Description of the test cases follows.

The first line of each test case contains an integer nn ( 2n21052 \leq n \leq 2 \cdot 10^5 ) — the number of vertices of the graph.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 106ai106-10^6 \leq a_i \leq 10^6 ).

The sum of nn for all test cases is at most 21052 \cdot 10^5 .

输出格式

For each test case, print a single line with the maximum value of f(t)f(t) (it can be shown that it is an integer), or INF if f(t)f(t) is not bounded above.

输入输出样例

  • 输入#1

    5
    2
    1 0
    2
    -1 1
    3
    1 -1 -2
    3
    3 -1 -2
    4
    1 2 3 -4

    输出#1

    INF
    -1
    INF
    -6
    -18
首页