CF1806C.Sequence Master

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

For some positive integer mm , YunQian considers an array qq of 2m2m (possibly negative) integers good, if and only if for every possible subsequence of qq that has length mm , the product of the mm elements in the subsequence is equal to the sum of the mm elements that are not in the subsequence. Formally, let U={1,2,,2m}U=\{1,2,\ldots,2m\} . For all sets SUS \subseteq U such that S=m|S|=m , iSqi=iUSqi\prod\limits_{i \in S} q_i = \sum\limits_{i \in U \setminus S} q_i .

Define the distance between two arrays aa and bb both of length kk to be i=1kaibi\sum\limits_{i=1}^k|a_i-b_i| .

You are given a positive integer nn and an array pp of 2n2n integers.

Find the minimum distance between pp and qq over all good arrays qq of length 2n2n . It can be shown for all positive integers nn , at least one good array exists. Note that you are not required to construct the array qq that achieves this minimum distance.

输入格式

The first line contains a single integer tt ( 1t1041\le t\le 10^4 ) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn ( 1n21051\le n\le 2\cdot10^5 ).

The second line of each test case contains 2n2n integers p1,p2,,p2np_1, p_2, \ldots, p_{2n} ( pi109|p_i| \le 10^9 ).

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot 10^5 .

输出格式

For each test case, output the minimum distance between pp and a good qq .

输入输出样例

  • 输入#1

    4
    1
    6 9
    2
    1 2 2 1
    2
    -2 -2 2 2
    4
    -3 -2 -1 0 1 2 3 4

    输出#1

    3
    2
    5
    13

说明/提示

In the first test case, it is optimal to let q=[6,6]q=[6,6] .

In the second test case, it is optimal to let q=[2,2,2,2]q=[2,2,2,2] .

首页