所有点对的 Angst 2AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given a positive integer $N$ and a length-$N$ sequence of positive integers $C=(C_1,C_2,\ldots,C_N)$.
给定一个正整数 $N$ 和一个长度为 $N$ 的正整数序列 $C=(C_1,C_2,\ldots,C_N)$。AI (CI翻译)
You want to prepare one or more cards, as many as you like, and write one integer between $1$ and $N$ (inclusive) on each of the front and back sides of each card, so that the following condition is satisfied.
现在,你希望准备任意多张卡片,并在每张卡片的正面和背面各写上一个 $1$ 到 $N$(含)之间的整数,使其满足以下条件。AI (CI翻译)
- No matter which distinct integers
$x$and$y$between$1$and$N$(inclusive) are chosen, there exists at least one card satisfying the following. - Exactly one of
$x$and$y$is written on at least one side of that card.
- 无论选择哪两个不同的
$1$到$N$(含)之间的整数$x$和$y$,都至少存在一张卡片满足以下条件。 - 在这张卡片的至少一面上写有
$x$和$y$中恰好一个。
It is allowed to write the same integer on the front and back of a single card.
允许在同一张卡片的正面和背面写上相同的整数。AI (CI翻译)
Here, the cost of writing $a$ on the front and $b$ on the back of a card is $C_a+C_b$.
在一张卡片正面写上 $a$、背面写上 $b$ 的代价为 $C_a+C_b$。AI (CI翻译)
Find the minimum total cost required to satisfy the condition.
求满足上述条件所需的最小总代价。AI (CI翻译)
You are given $T$ test cases; solve each of them.
给定 $T$ 个测试用例,请分别求出每个测试用例的答案。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1\le T\le 10^5$$2\le N\le 2\times 10^5$$1\le C_i\le 10^9$- The sum of
$N$over all test cases is at most$2\times 10^5$. - All input values are integers.
$1\le T\le 10^5$$2\le N\le 2\times 10^5$$1\le C_i\le 10^9$- 所有测试用例的
$N$之和不超过$2\times 10^5$。 - 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_TAI (CI翻译)
Each test case is given in the following format:
每个测试用例的格式如下:AI (CI翻译)
N
C_1 C_2 \ldots C_N
N
C_1 C_2 \ldots C_NAI (CI翻译)
Output
输出格式
AI (CI翻译)Output the answers for the test cases in order, separated by newlines.
按顺序输出各测试用例的答案,每个答案占一行。AI (CI翻译)
样例
3
3
3 2 5
4
5 6 7 8
7
12 42 21 10 29 33 18
9
23
145
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。