AT_arc229_f.Angst for All Pairs 2
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a positive integer N and a length-N sequence of positive integers C=(C1,C2,…,CN).
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.
- 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.
It is allowed to write the same integer on the front and back of a single card.
Here, the cost of writing a on the front and b on the back of a card is Ca+Cb.
Find the minimum total cost required to satisfy the condition.
You are given T test cases; solve each of them.
给你一个正整数 N 和一个长度为 N 的正整数序列 C=(C1,C2,…,CN)。
你需要制作一张或多张卡片(数量不限),并在每张卡片的正面和背面各写一个介于 1 到 N(含)之间的整数,使得满足以下条件:
- 对任意两个在 1 到 N(含)范围内的不同整数 x 和 y,都存在至少一张卡片,满足:
- x 和 y 中恰好有一个出现在该卡片的至少一面(正面或背面)上。
允许在一张卡片的正面和背面写相同的整数。
这里,若在某张卡片的正面写 a、背面写 b,则其花费为 Ca+Cb。
求满足上述条件所需的最小总花费。
你将得到 T 组测试数据;请分别求解每组数据。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N
C1 C2 … CN
输入从标准输入给出,格式如下:
T
case1
case2
⋮
caseT
每个测试用例的格式如下:
N
C1 C2 … CN
输出格式
Output the answers for the test cases in order, separated by newlines.
按顺序输出测试用例的答案,答案之间用换行符分隔。
输入输出样例
输入#1
3 3 3 2 5 4 5 6 7 8 7 12 42 21 10 29 33 18
输出#1
9 23 145
说明/提示
Sample 1 Explanation:
Consider the first test case.
By creating a card with 1 written on the front and 2 on the back, and a card with 2 written on the front and 2 on the back, the condition can be satisfied.
The total cost in this case is 3+2+2+2=9. It is impossible to satisfy the condition with a total cost less than 9, so output 9 on the first line.
Constraints
- 1≤T≤105
- 2≤N≤2×105
- 1≤Ci≤109
- The sum of N over all test cases is at most 2×105.
- All input values are integers.
样例 1 解释:
考虑第一个测试用例。
通过制作一张正面写有 1、背面写有 2 的卡片,以及一张正面写有 2、背面写有 2 的卡片,即可满足条件。
此时总花费为 3+2+2+2=9。无法以低于 9 的总花费满足条件,因此在第一行输出 9。
约束条件
- 1≤T≤105
- 2≤N≤2×105
- 1≤Ci≤109
- 所有测试用例的 N 之和不超过 2×105。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?